Package io.lettuce.core.dynamic
Class RedisCommandFactory
- 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 executeRedisCommand
s.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 newCommandFactory
givenStatefulConnection
.RedisCommandFactory(StatefulConnection<?,?> connection, Iterable<? extends RedisCodec<?,?>> redisCodecs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Commands>
TgetCommands(Class<T> commandInterface)
Returns a Redis Commands interface instance for the given interface.void
setCommandOutputFactoryResolver(CommandOutputFactoryResolver commandOutputFactoryResolver)
Set aCommandOutputFactoryResolver
.void
setVerifyCommandMethods(boolean verifyCommandMethods)
Enables/disables command verification which checks the command name against RedisCOMMAND
and the argument count.
-
-
-
Constructor Detail
-
RedisCommandFactory
public RedisCommandFactory(StatefulConnection<?,?> connection)
Create a newCommandFactory
givenStatefulConnection
.- Parameters:
connection
- must not benull
.
-
RedisCommandFactory
public RedisCommandFactory(StatefulConnection<?,?> connection, Iterable<? extends RedisCodec<?,?>> redisCodecs)
- Parameters:
connection
- must not benull
.redisCodecs
- must not benull
.
-
-
Method Detail
-
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 RedisCOMMAND
and the argument count.- Parameters:
verifyCommandMethods
-true
to enable command verification (default) orfalse
to disable command verification.
-
-