Class RedisConnection

  • All Implemented Interfaces:
    java.io.Closeable , java.lang.AutoCloseable

    
    public final class RedisConnection
     implements Closeable
                        

    A single connection to Redis.

    Not Thread safe and should not be shared between Threads. But is safe to be used as part of the RedisConnectionPool

    If an onResponse-handler throws, the remaining unread data is silently consumed (to keep the connection usable) and the exception is re-thrown.

    • Method Detail

      • getRedisStartupTime

         final Long getRedisStartupTime()

        Returns the time at which the Redis server was started, in epoch seconds. Useful for detecting whether Redis has been restarted (and might have lost data).

      • readResponse

         final RedisResponse readResponse()

        Reads a response from Redis, blocks if non-available. Not to be used directly, but by asynchronous code like RedisPubSubService

      • discardRemainingResponse

         final Unit discardRemainingResponse()

        Skips whatever has not been consumed yet of the response returned by readResponse. Not to be used directly, but by asynchronous code like RedisPubSubService

      • sendOnly

         final Unit sendOnly(RedisRequest command)

        Send commands without waiting for any responses. Not to be used directly, but by asynchronous code like RedisPubSubService

      • execTransactionPipeline

         final Boolean execTransactionPipeline(List<RedisRequest> commands)

        Wraps the given commands in a MULTI/EXEC transaction and execute them, using pipelining

        Parameters:
        commands - the commands to be executed inside the MULTI/EXEC block.
        Returns:

        true if the transaction succeeded, false if aborted (because a WATCHed key was modified)

      • execPipeline

         final Unit execPipeline(List<RedisRequest> commands)

        Sends the given commands to Redis using pipelining and calls the associated onResponse-handlers for each response

        Parameters:
        commands - the commands (and their onResponse-handlers) to be executed in the given order