Class ValkeyConnection

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

    
    public final class ValkeyConnection
     implements Closeable
                        

    A single connection to Valkey.

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

    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

      • getValkeyStartupTime

         final Long getValkeyStartupTime()

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

      • readResponse

         final ValkeyResponse readResponse()

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

      • 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 ValkeyPubSubService

      • sendOnly

         final Unit sendOnly(ValkeyRequest command)

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

      • execTransactionPipeline

         final Boolean execTransactionPipeline(List<ValkeyRequest> 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<ValkeyRequest> commands)

        Sends the given commands to Valkey 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