Class RedisConnectionMethods


  • public class RedisConnectionMethods
    extends io.toro.martini.redis.RedisBaseMethods
    • Constructor Detail

      • RedisConnectionMethods

        @Autowired
        RedisConnectionMethods​(io.toro.martini.database.DataSourceManager dataSourceManager)
    • Method Detail

      • connection

        public static io.toro.martini.database.LettuceRedisDataSource connection​(String redisConnectionName)
        Return Redis datasource object
        Parameters:
        redisConnectionName - the name of the saved database connection in Martini
        Returns:
        datasource
      • setTimeout

        public static void setTimeout​(@GloopParameter(allowNull=false)
                                      String connectionName,
                                      Duration timeout,
                                      GloopExecutionContext context)
        Set the default command timeout for this connection.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        timeout - Command timeout.
        Since:
        5.0
      • setTimeoutAsync

        public static void setTimeoutAsync​(@GloopParameter(allowNull=false)
                                           String connectionName,
                                           Duration timeout,
                                           GloopExecutionContext context)
        Asynchronously set the default command timeout for this connection.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        timeout - Command timeout.
        Since:
        5.0
      • dispatch

        public static RedisCommand dispatch​(@GloopParameter(allowNull=false)
                                            String connectionName,
                                            RedisCommand command,
                                            GloopExecutionContext context)
        Dispatch a command. Write a command on the channel. The command may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        command - the Redis command.
        Returns:
        the written Redis command.
      • dispatch

        public static Collection<RedisCommand> dispatch​(@GloopParameter(allowNull=false)
                                                        String connectionName,
                                                        Collection<? extends RedisCommand> commands,
                                                        GloopExecutionContext context)
        Dispatch multiple command in a single write on the channel. The commands may be changed/wrapped during write and the written instance is returned after the call. This command does not wait until the command completes and does not guarantee whether the command is executed successfully.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        commands - the Redis commands.
        Returns:
        the written Redis commands.
        Since:
        5.0
      • isOpen

        public static boolean isOpen​(@GloopParameter(allowNull=false)
                                     String connectionName,
                                     GloopExecutionContext context)
        Checks whether the connection to Redis is open or not
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        true if the connection is open (connected and not closed).
      • reset

        public static void reset​(@GloopParameter(allowNull=false)
                                 String connectionName,
                                 GloopExecutionContext context)
        Reset the command state. Queued commands will be canceled and the internal state will be reset. This is useful when the internal state machine gets out of sync with the connection.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
      • resetAsync

        public static void resetAsync​(@GloopParameter(allowNull=false)
                                      String connectionName,
                                      GloopExecutionContext context)
        Asynchronously reset the command state. queued commands will be canceled and the internal state will be reset. this is useful when the internal state machine gets out of sync with the connection.
        Parameters:
        connectionName - the Martini Runtime redis connection pool name
      • setAutoFlushCommands

        public static void setAutoFlushCommands​(@GloopParameter(allowNull=false)
                                                String connectionName,
                                                boolean autoFlush,
                                                GloopExecutionContext context)
        Disable or enable auto-flush behavior. Default is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a #flushCommands(String) is issued. After calling #flushCommands(String) commands are sent to the transport and executed by Redis.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        autoFlush - state of autoFlush.
      • setAutoFlushCommandsAsync

        public static void setAutoFlushCommandsAsync​(@GloopParameter(allowNull=false)
                                                     String connectionName,
                                                     boolean autoFlush,
                                                     GloopExecutionContext context)
        Disable or enable auto-flush behavior. Default is true. If autoFlushCommands is disabled, multiple commands can be issued without writing them actually to the transport. Commands are buffered until a #flushCommands(String) is issued. After calling #flushCommands(String) commands are sent to the transport and executed by Redis.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        autoFlush - state of autoFlush.
      • flushCommands

        public static void flushCommands​(@GloopParameter(allowNull=false)
                                         String connectionName,
                                         GloopExecutionContext context)
        Flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
      • flushCommandsAsync

        public static void flushCommandsAsync​(@GloopParameter(allowNull=false)
                                              String connectionName,
                                              GloopExecutionContext context)
        Asynchronously flush pending commands. This commands forces a flush on the channel and can be used to buffer ("pipeline") commands to achieve batching. No-op if channel is not connected.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
      • pubsubChannelsAsync

        @GloopParameter(name="redisFuturePubsubChannelsOutput")
        public static Future<List<Object>> pubsubChannelsAsync​(@GloopParameter(allowNull=false)
                                                               String connectionName,
                                                               GloopExecutionContext context)
        Asynchronously lists the currently *active channels*.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        list<K> array-reply a list of active channels, optionally matching the specified pattern.
      • pubsubNumsub

        @GloopObjectParameter("output{\nredisMap[]{\n  name:object\n  value:object\n}\n}")
        public static GloopModel pubsubNumsub​(@GloopParameter(allowNull=false)
                                              String connectionName,
                                              GloopExecutionContext context,
                                              @GloopParameter(allowNull=false)
                                              Object... channels)
        Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        channels - channel keys
        Returns:
        array-reply a list of channels and number of subscribers for every channel.
      • pubsubNumpat

        @GloopParameter(name="redisPubsubNumpatOutput")
        public static Long pubsubNumpat​(@GloopParameter(allowNull=false)
                                        String connectionName,
                                        GloopExecutionContext context)
        Returns the number of subscriptions to patterns.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        Long integer-reply the number of patterns all the clients are subscribed to.
      • pubsubNumpatAsync

        @GloopParameter(name="redisFuturePubsubNumpatOutput")
        public static Future<Long> pubsubNumpatAsync​(@GloopParameter(allowNull=false)
                                                     String connectionName,
                                                     GloopExecutionContext context)
        Asynchronously returns the number of subscriptions to patterns.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        long integer-reply the number of patterns all the clients are subscribed to.
      • role

        @GloopParameter(name="redisRoleOutput")
        public static List<Object> role​(@GloopParameter(allowNull=false)
                                        String connectionName,
                                        GloopExecutionContext context)
        Return the role of the instance in the context of replication.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        List<Object> array-reply where the first element is one of master, slave, sentinel and the additional elements are role-specific.
      • roleAsync

        @GloopParameter(name="redisFutureRoleOutput")
        public static Future<List<Object>> roleAsync​(@GloopParameter(allowNull=false)
                                                     String connectionName,
                                                     GloopExecutionContext context)
        Asynchronously return the role of the instance in the context of replication.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        list<Object> array-reply where the first element is one of master, slave, sentinel and the additional elements are role-specific.
      • readWriteAsync

        @GloopParameter(name="redisFutureReadWriteOutput")
        public static Future<String> readWriteAsync​(@GloopParameter(allowNull=false)
                                                    String connectionName,
                                                    GloopExecutionContext context)
        Asynchronously switch connection to read-Write mode (default) when connecting to a cluster.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        string simple-string-reply.
      • quit

        @GloopParameter(name="redisQuitOutput")
        public static String quit​(@GloopParameter(allowNull=false)
                                  String connectionName,
                                  GloopExecutionContext context)
        Instructs Redis to disconnect the connection. Note that if auto-reconnect is enabled then Lettuce will auto-reconnect if the connection was disconnected. Use StatefulConnection.close() to close connections and release resources.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        String simple-string-reply always OK.
      • quitAsync

        @GloopParameter(name="redisFutureQuitOutput")
        public static Future<String> quitAsync​(@GloopParameter(allowNull=false)
                                               String connectionName,
                                               GloopExecutionContext context)
        Asynchronously instructs redis to disconnect the connection. note that if auto-reconnect is enabled then lettuce will auto-reconnect if the connection was disconnected. use StatefulConnection.close() to close connections and release resources.
        Parameters:
        connectionName - The Martini Runtime Redis connection pool name
        Returns:
        string simple-string-reply always oK.