Class 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
    • Method Detail

      • setVerifyCommandMethods

        public void setVerifyCommandMethods​(boolean verifyCommandMethods)
        Enables/disables command verification which checks the command name against Redis COMMAND and the argument count.
        Parameters:
        verifyCommandMethods - true to enable command verification (default) or false to disable command verification.
      • getCommands

        public <T extends Commands> T getCommands​(Class<T> commandInterface)
        Returns a Redis Commands interface instance for the given interface.
        Type Parameters:
        T - command interface type.
        Parameters:
        commandInterface - must not be null.
        Returns:
        the implemented Redis Commands interface.