diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index 765e2950ee..095f3c36c3 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -5,7 +5,6 @@ import java.util.stream.Collectors; import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.resps.*; import redis.clients.jedis.resps.LCSMatchResult.MatchedPosition; import redis.clients.jedis.resps.LCSMatchResult.Position; @@ -1822,21 +1821,11 @@ public String toString() { } }; - public static final Builder> LIBRARY_LIST = new Builder>() { - @Override - public List build(Object data) { - List list = (List) data; - return list.stream().map(o -> LibraryInfo.LIBRARY_BUILDER.build(o)).collect(Collectors.toList()); - } - }; - - public static final Builder> GEARS_LIBRARY_LIST = new Builder>() { - @Override - public List build(Object data) { - List list = (List) data; - return list.stream().map(o -> GearsLibraryInfo.LIBRARY_BUILDER.build(o)).collect(Collectors.toList()); - } - }; + /** + * @deprecated Use {@link LibraryInfo#LIBRARY_INFO_LIST}. + */ + @Deprecated + public static final Builder> LIBRARY_LIST = LibraryInfo.LIBRARY_INFO_LIST; public static final Builder>> STRING_LIST_LIST = new Builder>>() { @Override diff --git a/src/main/java/redis/clients/jedis/CommandArguments.java b/src/main/java/redis/clients/jedis/CommandArguments.java index 77793fc378..1cdb4838bb 100644 --- a/src/main/java/redis/clients/jedis/CommandArguments.java +++ b/src/main/java/redis/clients/jedis/CommandArguments.java @@ -82,6 +82,11 @@ public final CommandArguments keys(Object... keys) { return this; } + public final CommandArguments keys(Collection keys) { + keys.forEach(key -> key(key)); + return this; + } + public final CommandArguments addParams(IParams params) { params.addParams(this); return this; diff --git a/src/main/java/redis/clients/jedis/CommandObjects.java b/src/main/java/redis/clients/jedis/CommandObjects.java index e6034f4b6e..708db5fc5a 100644 --- a/src/main/java/redis/clients/jedis/CommandObjects.java +++ b/src/main/java/redis/clients/jedis/CommandObjects.java @@ -2,8 +2,6 @@ import static redis.clients.jedis.Protocol.Command.*; import static redis.clients.jedis.Protocol.Keyword.*; -import static redis.clients.jedis.gears.RedisGearsProtocol.GearsCommand.TFCALL; -import static redis.clients.jedis.gears.RedisGearsProtocol.GearsCommand.TFCALLASYNC; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -18,10 +16,8 @@ import redis.clients.jedis.bloom.*; import redis.clients.jedis.bloom.RedisBloomProtocol.*; import redis.clients.jedis.commands.ProtocolCommand; -import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; -import redis.clients.jedis.gears.RedisGearsProtocol.GearsCommand; -import redis.clients.jedis.gears.TFunctionListParams; -import redis.clients.jedis.gears.TFunctionLoadParams; +import redis.clients.jedis.gears.*; +import redis.clients.jedis.gears.RedisGearsProtocol.*; import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.graph.GraphProtocol.*; import redis.clients.jedis.json.*; @@ -2706,19 +2702,13 @@ public final CommandObject eval(String script, int keyCount, String... p } public final CommandObject eval(String script, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(EVAL).add(script).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVAL).add(script).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject evalReadonly(String script, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(EVAL_RO).add(script).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVAL_RO).add(script).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject eval(byte[] script) { @@ -2736,19 +2726,13 @@ public final CommandObject eval(byte[] script, int keyCount, byte[]... p } public final CommandObject eval(byte[] script, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(EVAL).add(script).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(EVAL).add(script).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject evalReadonly(byte[] script, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(EVAL_RO).add(script).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(EVAL_RO).add(script).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject evalsha(String sha1) { @@ -2766,19 +2750,13 @@ public final CommandObject evalsha(String sha1, int keyCount, String... } public final CommandObject evalsha(String sha1, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject evalshaReadonly(String sha1, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(EVALSHA_RO).add(sha1).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA_RO).add(sha1).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject evalsha(byte[] sha1) { @@ -2796,19 +2774,13 @@ public final CommandObject evalsha(byte[] sha1, int keyCount, byte[]... } public final CommandObject evalsha(byte[] sha1, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA).add(sha1).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject evalshaReadonly(byte[] sha1, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(EVALSHA_RO).add(sha1).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(EVALSHA_RO).add(sha1).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject> scriptExists(List sha1s) { @@ -2880,19 +2852,13 @@ public final CommandObject slowlogReset() { } public final CommandObject fcall(String name, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(FCALL).add(name).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(FCALL).add(name).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject fcallReadonly(String name, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(FCALL_RO).add(name).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(FCALL_RO).add(name).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject functionDelete(String libraryName) { @@ -2900,21 +2866,21 @@ public final CommandObject functionDelete(String libraryName) { } public final CommandObject> functionList() { - return new CommandObject<>(commandArguments(FUNCTION).add(LIST), BuilderFactory.LIBRARY_LIST); + return new CommandObject<>(commandArguments(FUNCTION).add(LIST), LibraryInfo.LIBRARY_INFO_LIST); } public final CommandObject> functionList(String libraryNamePattern) { return new CommandObject<>(commandArguments(FUNCTION).add(LIST).add(LIBRARYNAME) - .add(libraryNamePattern), BuilderFactory.LIBRARY_LIST); + .add(libraryNamePattern), LibraryInfo.LIBRARY_INFO_LIST); } public final CommandObject> functionListWithCode() { - return new CommandObject<>(commandArguments(FUNCTION).add(LIST).add(WITHCODE), BuilderFactory.LIBRARY_LIST); + return new CommandObject<>(commandArguments(FUNCTION).add(LIST).add(WITHCODE), LibraryInfo.LIBRARY_INFO_LIST); } public final CommandObject> functionListWithCode(String libraryNamePattern) { return new CommandObject<>(commandArguments(FUNCTION).add(LIST).add(LIBRARYNAME) - .add(libraryNamePattern).add(WITHCODE), BuilderFactory.LIBRARY_LIST); + .add(libraryNamePattern).add(WITHCODE), LibraryInfo.LIBRARY_INFO_LIST); } public final CommandObject functionLoad(String functionCode) { @@ -2946,19 +2912,13 @@ public final CommandObject functionKill() { } public final CommandObject fcall(byte[] name, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(FCALL).add(name).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(FCALL).add(name).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject fcallReadonly(byte[] name, List keys, List args) { - byte[][] keysArray = keys.toArray(new byte[keys.size()][]); - byte[][] argsArray = args.toArray(new byte[args.size()][]); - return new CommandObject<>(commandArguments(FCALL_RO).add(name).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.RAW_OBJECT); + return new CommandObject<>(commandArguments(FCALL_RO).add(name).add(keys.size()) + .keys(keys).addObjects(args), BuilderFactory.RAW_OBJECT); } public final CommandObject functionDelete(byte[] libraryName) { @@ -4045,11 +4005,13 @@ public final CommandObject> cfInfo(String key) { } public final CommandObject cmsInitByDim(String key, long width, long depth) { - return new CommandObject<>(commandArguments(CountMinSketchCommand.INITBYDIM).key(key).add(width).add(depth), BuilderFactory.STRING); + return new CommandObject<>(commandArguments(CountMinSketchCommand.INITBYDIM).key(key).add(width) + .add(depth), BuilderFactory.STRING); } public final CommandObject cmsInitByProb(String key, double error, double probability) { - return new CommandObject<>(commandArguments(CountMinSketchCommand.INITBYPROB).key(key).add(error).add(probability), BuilderFactory.STRING); + return new CommandObject<>(commandArguments(CountMinSketchCommand.INITBYPROB).key(key).add(error) + .add(probability), BuilderFactory.STRING); } public final CommandObject> cmsIncrBy(String key, Map itemIncrements) { @@ -4059,7 +4021,8 @@ public final CommandObject> cmsIncrBy(String key, Map i } public final CommandObject> cmsQuery(String key, String... items) { - return new CommandObject<>(commandArguments(CountMinSketchCommand.QUERY).key(key).addObjects((Object[]) items), BuilderFactory.LONG_LIST); + return new CommandObject<>(commandArguments(CountMinSketchCommand.QUERY).key(key) + .addObjects((Object[]) items), BuilderFactory.LONG_LIST); } public final CommandObject cmsMerge(String destKey, String... keys) { @@ -4226,48 +4189,30 @@ public final CommandObject> graphConfigGet(String configName // RedisGraph commands // RedisGears commands - public final CommandObject tFunctionLoad(String libraryCode, TFunctionLoadParams params) { - CommandArguments args = commandArguments(GearsCommand.TFUNCTION); - args.add(GearsKeyword.LOAD.getValue()); - params.addParams(args); - args.add(libraryCode); - - return new CommandObject<>(args, BuilderFactory.STRING); + return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LOAD) + .addParams(params).add(libraryCode), BuilderFactory.STRING); } public final CommandObject tFunctionDelete(String libraryName) { - CommandArguments args = commandArguments(GearsCommand.TFUNCTION); - args.add(GearsKeyword.DELETE.getValue()); - args.add(libraryName); - - return new CommandObject<>(args, BuilderFactory.STRING); + return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.DELETE) + .add(libraryName), BuilderFactory.STRING); } public final CommandObject> tFunctionList(TFunctionListParams params) { - CommandArguments args = commandArguments(GearsCommand.TFUNCTION); - args.add(GearsKeyword.LIST.getValue()); - params.addParams(args); - - return new CommandObject<>(args, BuilderFactory.GEARS_LIBRARY_LIST); + return new CommandObject<>(commandArguments(GearsCommand.TFUNCTION).add(GearsKeyword.LIST) + .addParams(params), GearsLibraryInfo.GEARS_LIBRARY_INFO_LIST); } public final CommandObject tFunctionCall(String library, String function, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(TFCALL).add(library+"."+function).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(GearsCommand.TFCALL).add(library + "." + function) + .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } public final CommandObject tFunctionCallAsync(String library, String function, List keys, List args) { - String[] keysArray = keys.toArray(new String[keys.size()]); - String[] argsArray = args.toArray(new String[args.size()]); - return new CommandObject<>(commandArguments(TFCALLASYNC).add(library+"."+function).add(keysArray.length) - .keys((Object[]) keysArray).addObjects((Object[]) argsArray), - BuilderFactory.ENCODED_OBJECT); + return new CommandObject<>(commandArguments(GearsCommand.TFCALLASYNC).add(library + "." + function) + .add(keys.size()).keys(keys).addObjects(args), BuilderFactory.ENCODED_OBJECT); } - // RedisGears commands /** diff --git a/src/main/java/redis/clients/jedis/UnifiedJedis.java b/src/main/java/redis/clients/jedis/UnifiedJedis.java index 51f64445bc..df3516eee6 100644 --- a/src/main/java/redis/clients/jedis/UnifiedJedis.java +++ b/src/main/java/redis/clients/jedis/UnifiedJedis.java @@ -4792,6 +4792,33 @@ public Map graphConfigGet(String configName) { } // RedisGraph commands + // RedisGears commands + @Override + public String tFunctionLoad(String libraryCode, TFunctionLoadParams params) { + return executeCommand(commandObjects.tFunctionLoad(libraryCode, params)); + } + + @Override + public String tFunctionDelete(String libraryName) { + return executeCommand(commandObjects.tFunctionDelete(libraryName)); + } + + @Override + public List tFunctionList(TFunctionListParams params) { + return executeCommand(commandObjects.tFunctionList(params)); + } + + @Override + public Object tFunctionCall(String library, String function, List keys, List args) { + return executeCommand(commandObjects.tFunctionCall(library, function, keys, args)); + } + + @Override + public Object tFunctionCallAsync(String library, String function, List keys, List args) { + return executeCommand(commandObjects.tFunctionCallAsync(library, function, keys, args)); + } + // RedisGears commands + public PipelineBase pipelined() { if (provider == null) { throw new IllegalStateException("It is not allowed to create Pipeline from this " + getClass()); @@ -4853,43 +4880,4 @@ public void setJsonObjectMapper(JsonObjectMapper jsonObjectMapper) { public void setDefaultSearchDialect(int dialect) { this.commandObjects.setDefaultSearchDialect(dialect); } - - // RedisGears commands - - @Override - public String tFunctionLoad(String libraryCode) { - return executeCommand(commandObjects.tFunctionLoad(libraryCode, TFunctionLoadParams.loadParams())); - } - - @Override - public String tFunctionLoad(String libraryCode, TFunctionLoadParams params) { - return executeCommand(commandObjects.tFunctionLoad(libraryCode, params)); - } - - @Override - public String tFunctionDelete(String libraryName) { - return executeCommand(commandObjects.tFunctionDelete(libraryName)); - } - - @Override - public List tFunctionList() { - return executeCommand(commandObjects.tFunctionList(TFunctionListParams.listParams())); - } - - @Override - public List tFunctionList(TFunctionListParams params) { - return executeCommand(commandObjects.tFunctionList(params)); - } - - @Override - public Object tFunctionCall(String library, String function, List keys, List args) { - return executeCommand(commandObjects.tFunctionCall(library, function, keys, args)); - } - - @Override - public Object tFunctionCallAsync(String library, String function, List keys, List args) { - return executeCommand(commandObjects.tFunctionCallAsync(library, function, keys, args)); - } - - // RedisGears commands } diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java b/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java index d8099a12e1..f5adb42c9e 100644 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java +++ b/src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java @@ -5,11 +5,22 @@ import java.util.List; public interface RedisGearsCommands { - String tFunctionLoad(String libraryCode); + + default String tFunctionLoad(String libraryCode) { + return tFunctionLoad(libraryCode, TFunctionLoadParams.loadParams()); + } + String tFunctionLoad(String libraryCode, TFunctionLoadParams params); + + default List tFunctionList() { + return tFunctionList(TFunctionListParams.listParams()); + } + List tFunctionList(TFunctionListParams params); - List tFunctionList(); + String tFunctionDelete(String libraryName); + Object tFunctionCall(String library, String function, List keys, List args); + Object tFunctionCallAsync(String library, String function, List keys, List args); } diff --git a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java b/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java index 7a918d6152..fc43f29e66 100644 --- a/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java +++ b/src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java @@ -1,18 +1,21 @@ package redis.clients.jedis.gears; +import redis.clients.jedis.args.Rawable; import redis.clients.jedis.commands.ProtocolCommand; import redis.clients.jedis.util.SafeEncoder; public class RedisGearsProtocol { + public enum GearsCommand implements ProtocolCommand { - TFUNCTION("TFUNCTION"), - TFCALL("TFCALL"), - TFCALLASYNC("TFCALLASYNC"); + + TFUNCTION, + TFCALL, + TFCALLASYNC; private final byte[] raw; - GearsCommand(String alt) { - raw = SafeEncoder.encode(alt); + private GearsCommand() { + this.raw = SafeEncoder.encode(name()); } @Override @@ -21,24 +24,26 @@ public byte[] getRaw() { } } - public enum GearsKeyword { - CONFIG("CONFIG"), - REPLACE("REPLACE"), - LOAD("LOAD"), - DELETE("DELETE"), - LIST("LIST"), - WITHCODE("WITHCODE"), - LIBRARY("LIBRARY"), - VERBOSE("VERBOSE"); + public enum GearsKeyword implements Rawable { - private final String value; + CONFIG, + REPLACE, + LOAD, + DELETE, + LIST, + WITHCODE, + LIBRARY, + VERBOSE; + + private final byte[] raw; - GearsKeyword(String value) { - this.value = value; + private GearsKeyword() { + this.raw = SafeEncoder.encode(name()); } - public String getValue() { - return value; + @Override + public byte[] getRaw() { + return raw; } } } diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java index 82b3b2d128..d3f867e92b 100644 --- a/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java +++ b/src/main/java/redis/clients/jedis/gears/TFunctionListParams.java @@ -18,7 +18,7 @@ public static TFunctionListParams listParams() { @Override public void addParams(CommandArguments args) { if (withCode) { - args.add(GearsKeyword.WITHCODE.getValue()); + args.add(GearsKeyword.WITHCODE); } if (verbose > 0 && verbose < 4) { @@ -28,8 +28,7 @@ public void addParams(CommandArguments args) { } if (libraryName != null) { - args.add(GearsKeyword.LIBRARY); - args.add(libraryName); + args.add(GearsKeyword.LIBRARY).add(libraryName); } } diff --git a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java b/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java index 087069e142..d155727ec5 100644 --- a/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java +++ b/src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java @@ -15,12 +15,11 @@ public static TFunctionLoadParams loadParams() { @Override public void addParams(CommandArguments args) { if (replace) { - args.add(GearsKeyword.REPLACE.getValue()); + args.add(GearsKeyword.REPLACE); } if (config != null && !config.isEmpty()) { - args.add(GearsKeyword.CONFIG.getValue()); - args.add(config); + args.add(GearsKeyword.CONFIG).add(config); } } @@ -29,7 +28,7 @@ public TFunctionLoadParams replace() { return this; } - public TFunctionLoadParams withConfig(String config) { + public TFunctionLoadParams config(String config) { this.config = config; return this; } diff --git a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java b/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java index 5dfb86b88a..77f0351336 100644 --- a/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java +++ b/src/main/java/redis/clients/jedis/gears/resps/GearsLibraryInfo.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import static redis.clients.jedis.BuilderFactory.*; import static redis.clients.jedis.gears.resps.FunctionInfo.FUNCTION_INFO_LIST; @@ -89,7 +90,7 @@ public String getUser() { return user; } - public static final Builder LIBRARY_BUILDER = new Builder() { + public static final Builder GEARS_LIBRARY_INFO = new Builder() { @Override public GearsLibraryInfo build(Object data) { if (data == null) return null; @@ -169,4 +170,13 @@ public GearsLibraryInfo build(Object data) { return new GearsLibraryInfo(apiVersion, clusterFunctions, code, configuration, engine, functions, keyspaceTriggers, name, pendingAsyncCalls, pendingJobs, streamTriggers, user); } }; + + public static final Builder> GEARS_LIBRARY_INFO_LIST = new Builder>() { + @Override + public List build(Object data) { + List list = (List) data; + return list.stream().map(o -> GearsLibraryInfo.GEARS_LIBRARY_INFO.build(o)).collect(Collectors.toList()); + } + }; + } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/resps/LibraryInfo.java b/src/main/java/redis/clients/jedis/resps/LibraryInfo.java index 6471ac9ba7..41cbd49dd3 100644 --- a/src/main/java/redis/clients/jedis/resps/LibraryInfo.java +++ b/src/main/java/redis/clients/jedis/resps/LibraryInfo.java @@ -47,7 +47,7 @@ public String getLibraryCode() { return libraryCode; } - public static final Builder LIBRARY_BUILDER = new Builder() { + public static final Builder LIBRARY_INFO = new Builder() { @Override public LibraryInfo build(Object data) { if (data == null) return null; @@ -88,4 +88,18 @@ public LibraryInfo build(Object data) { } }; + /** + * @deprecated Use {@link LibraryInfo#LIBRARY_INFO}. + */ + @Deprecated + public static final Builder LIBRARY_BUILDER = LIBRARY_INFO; + + public static final Builder> LIBRARY_INFO_LIST = new Builder>() { + @Override + public List build(Object data) { + List list = (List) data; + return list.stream().map(o -> LibraryInfo.LIBRARY_INFO.build(o)).collect(Collectors.toList()); + } + }; + } diff --git a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java index 0a2695713e..99086d10e5 100644 --- a/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java +++ b/src/test/java/redis/clients/jedis/modules/gears/GearsTest.java @@ -3,14 +3,13 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import redis.clients.jedis.RedisProtocol; + import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.gears.TFunctionListParams; import redis.clients.jedis.gears.TFunctionLoadParams; import redis.clients.jedis.modules.RedisModuleCommandsTestBase; import redis.clients.jedis.gears.resps.GearsLibraryInfo; import redis.clients.jedis.util.KeyValue; -import redis.clients.jedis.util.RedisProtocolUtil; import java.io.IOException; import java.nio.file.Files; @@ -474,7 +473,7 @@ public void testFunctionLoadWithConfig() throws IOException { client.tFunctionCall("withConfig", "hset", Collections.emptyList(), argsBefore); String config = "{\"last_modified_field_name\":\"changed_on\"}"; - client.tFunctionLoad(readLibrary("withConfig.js"), TFunctionLoadParams.loadParams().replace().withConfig(config)); + client.tFunctionLoad(readLibrary("withConfig.js"), TFunctionLoadParams.loadParams().replace().config(config)); List argsAfter = Arrays.asList("Dictionary2", "Gallina", "Hen"); Object result = client.tFunctionCall("withConfig", "hset", Collections.emptyList(), argsAfter);