-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Triggers and functions commands
- Loading branch information
Showing
20 changed files
with
1,519 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/redis/clients/jedis/gears/RedisGearsCommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package redis.clients.jedis.gears; | ||
|
||
import redis.clients.jedis.gears.resps.GearsLibraryInfo; | ||
|
||
import java.util.List; | ||
|
||
public interface RedisGearsCommands { | ||
String tFunctionLoad(String libraryCode); | ||
String tFunctionLoad(String libraryCode, TFunctionLoadParams params); | ||
List<GearsLibraryInfo> tFunctionList(TFunctionListParams params); | ||
List<GearsLibraryInfo> tFunctionList(); | ||
String tFunctionDelete(String libraryName); | ||
Object tFunctionCall(String library, String function, List<String> keys, List<String> args); | ||
Object tFunctionCallAsync(String library, String function, List<String> keys, List<String> args); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/redis/clients/jedis/gears/RedisGearsProtocol.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package redis.clients.jedis.gears; | ||
|
||
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"); | ||
|
||
private final byte[] raw; | ||
|
||
GearsCommand(String alt) { | ||
raw = SafeEncoder.encode(alt); | ||
} | ||
|
||
@Override | ||
public byte[] getRaw() { | ||
return raw; | ||
} | ||
} | ||
|
||
public enum GearsKeyword { | ||
CONFIG("CONFIG"), | ||
REPLACE("REPLACE"), | ||
LOAD("LOAD"), | ||
DELETE("DELETE"), | ||
LIST("LIST"), | ||
WITHCODE("WITHCODE"), | ||
LIBRARY("LIBRARY"), | ||
VERBOSE("VERBOSE"); | ||
|
||
private final String value; | ||
|
||
GearsKeyword(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/redis/clients/jedis/gears/TFunctionListParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package redis.clients.jedis.gears; | ||
|
||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; | ||
import redis.clients.jedis.params.IParams; | ||
|
||
import java.util.Collections; | ||
|
||
public class TFunctionListParams implements IParams { | ||
private boolean withCode = false; | ||
private int verbose; | ||
private String libraryName; | ||
|
||
public static TFunctionListParams listParams() { | ||
return new TFunctionListParams(); | ||
} | ||
|
||
@Override | ||
public void addParams(CommandArguments args) { | ||
if (withCode) { | ||
args.add(GearsKeyword.WITHCODE.getValue()); | ||
} | ||
|
||
if (verbose > 0 && verbose < 4) { | ||
args.add(String.join("", Collections.nCopies(verbose, "v"))); | ||
} else if (verbose != 0) { // verbose == 0 is the default, so we don't need to throw an error | ||
throw new IllegalArgumentException("verbose must be between 1 and 3"); | ||
} | ||
|
||
if (libraryName != null) { | ||
args.add(GearsKeyword.LIBRARY); | ||
args.add(libraryName); | ||
} | ||
} | ||
|
||
public TFunctionListParams withCode() { | ||
this.withCode = true; | ||
return this; | ||
} | ||
|
||
public TFunctionListParams verbose(int verbose) { | ||
this.verbose = verbose; | ||
return this; | ||
} | ||
|
||
public TFunctionListParams library(String libraryName) { | ||
this.libraryName = libraryName; | ||
return this; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/redis/clients/jedis/gears/TFunctionLoadParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package redis.clients.jedis.gears; | ||
|
||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.gears.RedisGearsProtocol.GearsKeyword; | ||
import redis.clients.jedis.params.IParams; | ||
|
||
public class TFunctionLoadParams implements IParams { | ||
private boolean replace = false; | ||
private String config; | ||
|
||
public static TFunctionLoadParams loadParams() { | ||
return new TFunctionLoadParams(); | ||
} | ||
|
||
@Override | ||
public void addParams(CommandArguments args) { | ||
if (replace) { | ||
args.add(GearsKeyword.REPLACE.getValue()); | ||
} | ||
|
||
if (config != null && !config.isEmpty()) { | ||
args.add(GearsKeyword.CONFIG.getValue()); | ||
args.add(config); | ||
} | ||
} | ||
|
||
public TFunctionLoadParams replace() { | ||
this.replace = true; | ||
return this; | ||
} | ||
|
||
public TFunctionLoadParams withConfig(String config) { | ||
this.config = config; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.