java.lang.Object
io.lettuce.core.dynamic.RedisCommandFactory
public class RedisCommandFactory extends Object
Factory to create Redis Command interface instances.
This class is the entry point to implement command interfaces and obtain a reference to the implementation. Redis Command
interfaces provide a dynamic API that are declared in userland code. RedisCommandFactory and its supportive classes
analyze method declarations and derive from those factories to create and execute RedisCommands.
Example
public interface MyRedisCommands extends Commands {
String get(String key); // Synchronous Execution of GET
@Command("GET")
byte[] getAsBytes(String key); // Synchronous Execution of GET returning data as byte array
@Command("SET")
// synchronous execution applying a Timeout
String setSync(String key, String value, Timeout timeout);
Future<String> set(String key, String value); // asynchronous SET execution
@Command("SET")
Mono<String> setReactive(String key, String value, SetArgs setArgs); // reactive SET execution using SetArgs
@CommandNaming(split = DOT)
// support for Redis Module command notation -> NR.RUN
double nrRun(String key, int... indexes);
}
RedisCommandFactory factory = new RedisCommandFactory(connection);
MyRedisCommands commands = factory.getCommands(MyRedisCommands.class);
String value = commands.get("key");
- Since:
- 5.0
- Author:
- Mark Paluch
- See Also:
Command,CommandMethod
-
Constructor Summary
Constructors Constructor Description RedisCommandFactory(StatefulConnection<?,?> connection)Create a newCommandFactorygivenStatefulConnection.RedisCommandFactory(StatefulConnection<?,?> connection, Iterable<? extends RedisCodec<?,?>> redisCodecs) -
Method Summary
Modifier and Type Method Description <T extends Commands>
TgetCommands(Class<T> commandInterface)Returns a Redis Commands interface instance for the given interface.voidsetCommandOutputFactoryResolver(CommandOutputFactoryResolver commandOutputFactoryResolver)Set aCommandOutputFactoryResolver.voidsetVerifyCommandMethods(boolean verifyCommandMethods)Enables/disables command verification which checks the command name against RedisCOMMANDand the argument count.
-
Constructor Details
-
RedisCommandFactory
Create a newCommandFactorygivenStatefulConnection.- Parameters:
connection- must not benull.
-
RedisCommandFactory
public RedisCommandFactory(StatefulConnection<?,?> connection, Iterable<? extends RedisCodec<?,?>> redisCodecs)- Parameters:
connection- must not benull.redisCodecs- must not benull.
-
-
Method Details
-
setCommandOutputFactoryResolver
public void setCommandOutputFactoryResolver(CommandOutputFactoryResolver commandOutputFactoryResolver)Set aCommandOutputFactoryResolver.- Parameters:
commandOutputFactoryResolver- must not benull.
-
setVerifyCommandMethods
public void setVerifyCommandMethods(boolean verifyCommandMethods)Enables/disables command verification which checks the command name against RedisCOMMANDand the argument count.- Parameters:
verifyCommandMethods-trueto enable command verification (default) orfalseto disable command verification.
-
getCommands
Returns a Redis Commands interface instance for the given interface.- Type Parameters:
T- command interface type.- Parameters:
commandInterface- must not benull.- Returns:
- the implemented Redis Commands interface.
-