Class RedisClientProtocolHandler

java.lang.Object
org.bluezoo.gumdrop.redis.client.RedisClientProtocolHandler
All Implemented Interfaces:
ProtocolHandler, RedisSession

public class RedisClientProtocolHandler extends Object implements ProtocolHandler, RedisSession
Redis client protocol handler using RESP (Redis Serialization Protocol).

Implements ProtocolHandler and RedisSession, storing an Endpoint field set in connected(Endpoint) and delegating all I/O to the endpoint.

Commands are encoded as RESP arrays of bulk strings (RESP spec — "Sending commands to a Redis server") and sent via the endpoint. Responses are decoded by RESPDecoder and dispatched to the appropriate callback in FIFO order (RESP spec — "Pipelining").

Supported RESP2 response types:

RESP3 types (Map, Set, Double, Boolean, Null, Push, Verbatim String, Big Number, Blob Error) are decoded and dispatched. RESP3 Maps received by ArrayResultHandler are flattened to alternating key/value lists. The HELLO command negotiates the RESP protocol version (RESP3).

Pub/Sub push messages are handled out-of-band when in Pub/Sub mode (RESP spec — "Pub/Sub" / "Push type"). In RESP3, Push (>) replaces the array-based Pub/Sub detection with a dedicated type.

Author:
Chris Burdess
See Also:
  • Constructor Details

    • RedisClientProtocolHandler

      public RedisClientProtocolHandler(RedisConnectionReady handler)
      Creates a Redis client endpoint handler.
      Parameters:
      handler - the client handler for callbacks
  • Method Details

    • connected

      public void connected(Endpoint ep)
      Description copied from interface: ProtocolHandler
      Called when the endpoint is established and ready for protocol traffic.

      The endpoint reference passed here should be stored by the handler for sending data and querying connection state.

      Specified by:
      connected in interface ProtocolHandler
      Parameters:
      ep - the endpoint that is now connected
    • receive

      public void receive(ByteBuffer buf)
      Description copied from interface: ProtocolHandler
      Called when plaintext application data is received from the peer.

      The buffer is in read mode (position at data start, limit at data end). The handler should consume as much data as it can. After this method returns, any unconsumed data (between the buffer's position and limit) will be preserved for the next call.

      Specified by:
      receive in interface ProtocolHandler
      Parameters:
      buf - the application data received
    • disconnected

      public void disconnected()
      Description copied from interface: ProtocolHandler
      Called when the peer has closed the connection or stream.

      After this method returns, the endpoint is no longer usable. Protocol handlers should perform any cleanup here.

      Specified by:
      disconnected in interface ProtocolHandler
    • securityEstablished

      public void securityEstablished(SecurityInfo info)
      Description copied from interface: ProtocolHandler
      Called when the security layer becomes active.

      For TCP with STARTTLS, this is called after the TLS handshake completes. For QUIC (always secure), this is called before ProtocolHandler.connected(Endpoint). For initially-secure TCP, this is also called before ProtocolHandler.connected(Endpoint).

      Protocol handlers that need to reset state after STARTTLS (e.g., SMTP EHLO re-issue) should do so here.

      Specified by:
      securityEstablished in interface ProtocolHandler
      Parameters:
      info - details about the negotiated security parameters
    • error

      public void error(Exception cause)
      Description copied from interface: ProtocolHandler
      Called when an unrecoverable error occurs on the endpoint.

      This covers I/O errors, TLS handshake failures, and connection failures for client-initiated endpoints. The endpoint may or may not be usable after this call.

      Specified by:
      error in interface ProtocolHandler
      Parameters:
      cause - the exception that caused the error
    • close

      public void close()
      Description copied from interface: RedisSession
      Closes the connection immediately.
      Specified by:
      close in interface RedisSession
    • auth

      public void auth(String password, StringResultHandler h)
      Description copied from interface: RedisSession
      Authenticates with a password (Redis 5 and earlier).
      Specified by:
      auth in interface RedisSession
      Parameters:
      password - the password
      h - the result handler
    • auth

      public void auth(String username, String password, StringResultHandler h)
      Description copied from interface: RedisSession
      Authenticates with username and password (Redis 6+ ACL).
      Specified by:
      auth in interface RedisSession
      Parameters:
      username - the username
      password - the password
      h - the result handler
    • hello

      public void hello(int protover, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Sends a HELLO command to negotiate the RESP protocol version and optionally authenticate in a single round-trip (Redis 6+).

      HELLO returns a map of server properties including: server, version, proto, id, mode, role, modules.

      Specified by:
      hello in interface RedisSession
      Parameters:
      protover - the RESP protocol version (2 or 3)
      h - receives the server properties as an array
    • hello

      public void hello(int protover, String username, String password, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Sends a HELLO command with authentication.
      Specified by:
      hello in interface RedisSession
      Parameters:
      protover - the RESP protocol version (2 or 3)
      username - the username (or "default")
      password - the password
      h - receives the server properties as an array
    • clientSetName

      public void clientSetName(String name, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets the connection name (visible in CLIENT LIST).
      Specified by:
      clientSetName in interface RedisSession
      Parameters:
      name - the connection name
      h - receives "OK"
    • clientGetName

      public void clientGetName(BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets the connection name.
      Specified by:
      clientGetName in interface RedisSession
      Parameters:
      h - receives the connection name or null
    • clientId

      public void clientId(IntegerResultHandler h)
      Description copied from interface: RedisSession
      Returns the unique client ID of the current connection.
      Specified by:
      clientId in interface RedisSession
      Parameters:
      h - receives the client ID
    • ping

      public void ping(StringResultHandler h)
      Description copied from interface: RedisSession
      Sends a PING command.
      Specified by:
      ping in interface RedisSession
      Parameters:
      h - receives "PONG"
    • ping

      public void ping(String message, BulkResultHandler h)
      Description copied from interface: RedisSession
      Sends a PING command with a message.
      Specified by:
      ping in interface RedisSession
      Parameters:
      message - the message to echo
      h - receives the message back
    • select

      public void select(int index, StringResultHandler h)
      Description copied from interface: RedisSession
      Selects a database by index.
      Specified by:
      select in interface RedisSession
      Parameters:
      index - the database index (0-15 typically)
      h - the result handler
    • echo

      public void echo(String message, BulkResultHandler h)
      Description copied from interface: RedisSession
      Echoes a message.
      Specified by:
      echo in interface RedisSession
      Parameters:
      message - the message to echo
      h - receives the message back
    • quit

      public void quit()
      Description copied from interface: RedisSession
      Closes the connection gracefully.
      Specified by:
      quit in interface RedisSession
    • reset

      public void reset(StringResultHandler h)
      Description copied from interface: RedisSession
      Resets the connection state, clearing Pub/Sub subscriptions, MULTI transaction, WATCH keys, and authenticated user (Redis command reference — RESET).
      Specified by:
      reset in interface RedisSession
      Parameters:
      h - receives "RESET"
    • get

      public void get(String key, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets the value of a key.
      Specified by:
      get in interface RedisSession
      Parameters:
      key - the key
      h - receives the value or null
    • set

      public void set(String key, String value, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets a key to a string value.
      Specified by:
      set in interface RedisSession
      Parameters:
      key - the key
      value - the value
      h - receives "OK"
    • set

      public void set(String key, byte[] value, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets a key to a binary value.
      Specified by:
      set in interface RedisSession
      Parameters:
      key - the key
      value - the value bytes
      h - receives "OK"
    • setex

      public void setex(String key, int seconds, String value, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets a key with expiration in seconds.
      Specified by:
      setex in interface RedisSession
      Parameters:
      key - the key
      seconds - the expiration time in seconds
      value - the value
      h - receives "OK"
    • psetex

      public void psetex(String key, long milliseconds, String value, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets a key with expiration in milliseconds.
      Specified by:
      psetex in interface RedisSession
      Parameters:
      key - the key
      milliseconds - the expiration time in milliseconds
      value - the value
      h - receives "OK"
    • setnx

      public void setnx(String key, String value, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Sets a key only if it doesn't exist.
      Specified by:
      setnx in interface RedisSession
      Parameters:
      key - the key
      value - the value
      h - receives true if set, false if key existed
    • getset

      public void getset(String key, String value, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets the old value and sets a new value.
      Specified by:
      getset in interface RedisSession
      Parameters:
      key - the key
      value - the new value
      h - receives the old value or null
    • mget

      public void mget(ArrayResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Gets multiple keys.
      Specified by:
      mget in interface RedisSession
      Parameters:
      h - receives array of values (nulls for missing keys)
      keys - the keys
    • mset

      public void mset(StringResultHandler h, String... keysAndValues)
      Description copied from interface: RedisSession
      Sets multiple keys.
      Specified by:
      mset in interface RedisSession
      Parameters:
      h - receives "OK"
      keysAndValues - alternating keys and values
    • incr

      public void incr(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Increments an integer value.
      Specified by:
      incr in interface RedisSession
      Parameters:
      key - the key
      h - receives the new value
    • incrby

      public void incrby(String key, long increment, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Increments by a specific amount.
      Specified by:
      incrby in interface RedisSession
      Parameters:
      key - the key
      increment - the amount to add
      h - receives the new value
    • incrbyfloat

      public void incrbyfloat(String key, double increment, BulkResultHandler h)
      Description copied from interface: RedisSession
      Increments a float value.
      Specified by:
      incrbyfloat in interface RedisSession
      Parameters:
      key - the key
      increment - the amount to add
      h - receives the new value as a string
    • decr

      public void decr(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Decrements an integer value.
      Specified by:
      decr in interface RedisSession
      Parameters:
      key - the key
      h - receives the new value
    • decrby

      public void decrby(String key, long decrement, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Decrements by a specific amount.
      Specified by:
      decrby in interface RedisSession
      Parameters:
      key - the key
      decrement - the amount to subtract
      h - receives the new value
    • append

      public void append(String key, String value, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Appends a value to a string.
      Specified by:
      append in interface RedisSession
      Parameters:
      key - the key
      value - the value to append
      h - receives the new string length
    • strlen

      public void strlen(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the length of a string value.
      Specified by:
      strlen in interface RedisSession
      Parameters:
      key - the key
      h - receives the length
    • del

      public void del(IntegerResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Deletes one or more keys.
      Specified by:
      del in interface RedisSession
      Parameters:
      h - receives the count of keys deleted
      keys - the keys to delete
    • exists

      public void exists(String key, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Checks if a key exists.
      Specified by:
      exists in interface RedisSession
      Parameters:
      key - the key
      h - receives true if exists
    • exists

      public void exists(IntegerResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Checks how many of the specified keys exist.
      Specified by:
      exists in interface RedisSession
      Parameters:
      h - receives the count of existing keys
      keys - the keys to check
    • expire

      public void expire(String key, int seconds, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Sets an expiration time in seconds.
      Specified by:
      expire in interface RedisSession
      Parameters:
      key - the key
      seconds - the expiration time
      h - receives true if set, false if key doesn't exist
    • pexpire

      public void pexpire(String key, long milliseconds, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Sets an expiration time in milliseconds.
      Specified by:
      pexpire in interface RedisSession
      Parameters:
      key - the key
      milliseconds - the expiration time
      h - receives true if set, false if key doesn't exist
    • expireat

      public void expireat(String key, long timestamp, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Sets an expiration time as a Unix timestamp (seconds).
      Specified by:
      expireat in interface RedisSession
      Parameters:
      key - the key
      timestamp - the Unix timestamp
      h - receives true if set, false if key doesn't exist
    • ttl

      public void ttl(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the remaining time to live in seconds.
      Specified by:
      ttl in interface RedisSession
      Parameters:
      key - the key
      h - receives TTL, -1 if no expiry, -2 if key doesn't exist
    • pttl

      public void pttl(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the remaining time to live in milliseconds.
      Specified by:
      pttl in interface RedisSession
      Parameters:
      key - the key
      h - receives TTL, -1 if no expiry, -2 if key doesn't exist
    • persist

      public void persist(String key, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Removes the expiration from a key.
      Specified by:
      persist in interface RedisSession
      Parameters:
      key - the key
      h - receives true if removed, false if no expiry or key doesn't exist
    • keys

      public void keys(String pattern, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Finds all keys matching a pattern.
      Specified by:
      keys in interface RedisSession
      Parameters:
      pattern - the glob-style pattern
      h - receives the matching keys
    • rename

      public void rename(String oldKey, String newKey, StringResultHandler h)
      Description copied from interface: RedisSession
      Renames a key.
      Specified by:
      rename in interface RedisSession
      Parameters:
      oldKey - the current key name
      newKey - the new key name
      h - receives "OK"
    • renamenx

      public void renamenx(String oldKey, String newKey, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Renames a key only if the new key doesn't exist.
      Specified by:
      renamenx in interface RedisSession
      Parameters:
      oldKey - the current key name
      newKey - the new key name
      h - receives true if renamed, false if new key existed
    • type

      public void type(String key, StringResultHandler h)
      Description copied from interface: RedisSession
      Returns the type of a key.
      Specified by:
      type in interface RedisSession
      Parameters:
      key - the key
      h - receives the type (string, list, set, zset, hash, stream)
    • scan

      public void scan(String cursor, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over the key space.
      Specified by:
      scan in interface RedisSession
      Parameters:
      cursor - the cursor ("0" to start)
      h - receives the cursor and elements
    • scan

      public void scan(String cursor, String match, int count, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over the key space with MATCH and COUNT options.
      Specified by:
      scan in interface RedisSession
      Parameters:
      cursor - the cursor ("0" to start)
      match - the glob-style pattern (null to skip)
      count - the hint for number of elements (0 to skip)
      h - receives the cursor and elements
    • hscan

      public void hscan(String key, String cursor, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over fields in a hash.
      Specified by:
      hscan in interface RedisSession
      Parameters:
      key - the hash key
      cursor - the cursor ("0" to start)
      h - receives the cursor and field-value pairs
    • hscan

      public void hscan(String key, String cursor, String match, int count, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over fields in a hash with MATCH and COUNT.
      Specified by:
      hscan in interface RedisSession
      Parameters:
      key - the hash key
      cursor - the cursor ("0" to start)
      match - the glob-style pattern (null to skip)
      count - the hint for number of elements (0 to skip)
      h - receives the cursor and field-value pairs
    • sscan

      public void sscan(String key, String cursor, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over members of a set.
      Specified by:
      sscan in interface RedisSession
      Parameters:
      key - the set key
      cursor - the cursor ("0" to start)
      h - receives the cursor and members
    • sscan

      public void sscan(String key, String cursor, String match, int count, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over members of a set with MATCH and COUNT.
      Specified by:
      sscan in interface RedisSession
      Parameters:
      key - the set key
      cursor - the cursor ("0" to start)
      match - the glob-style pattern (null to skip)
      count - the hint for number of elements (0 to skip)
      h - receives the cursor and members
    • zscan

      public void zscan(String key, String cursor, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over members of a sorted set.
      Specified by:
      zscan in interface RedisSession
      Parameters:
      key - the sorted set key
      cursor - the cursor ("0" to start)
      h - receives the cursor and member-score pairs
    • zscan

      public void zscan(String key, String cursor, String match, int count, ScanResultHandler h)
      Description copied from interface: RedisSession
      Incrementally iterates over members of a sorted set with MATCH and COUNT.
      Specified by:
      zscan in interface RedisSession
      Parameters:
      key - the sorted set key
      cursor - the cursor ("0" to start)
      match - the glob-style pattern (null to skip)
      count - the hint for number of elements (0 to skip)
      h - receives the cursor and member-score pairs
    • hget

      public void hget(String key, String field, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets a hash field value.
      Specified by:
      hget in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      h - receives the value or null
    • hset

      public void hset(String key, String field, String value, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Sets a hash field.
      Specified by:
      hset in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      value - the value
      h - receives count of fields added (0 if updated, 1 if new)
    • hset

      public void hset(String key, String field, byte[] value, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Sets a hash field with binary value.
      Specified by:
      hset in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      value - the value bytes
      h - receives count of fields added
    • hsetnx

      public void hsetnx(String key, String field, String value, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Sets a hash field only if it doesn't exist.
      Specified by:
      hsetnx in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      value - the value
      h - receives true if set, false if field existed
    • hmget

      public void hmget(String key, ArrayResultHandler h, String... fields)
      Description copied from interface: RedisSession
      Gets multiple hash fields.
      Specified by:
      hmget in interface RedisSession
      Parameters:
      key - the key
      h - receives array of values
      fields - the field names
    • hmset

      public void hmset(String key, StringResultHandler h, String... fieldsAndValues)
      Description copied from interface: RedisSession
      Sets multiple hash fields.
      Specified by:
      hmset in interface RedisSession
      Parameters:
      key - the key
      h - receives "OK"
      fieldsAndValues - alternating field names and values
    • hgetall

      public void hgetall(String key, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets all fields and values in a hash.
      Specified by:
      hgetall in interface RedisSession
      Parameters:
      key - the key
      h - receives alternating field/value array
    • hkeys

      public void hkeys(String key, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets all field names in a hash.
      Specified by:
      hkeys in interface RedisSession
      Parameters:
      key - the key
      h - receives array of field names
    • hvals

      public void hvals(String key, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets all values in a hash.
      Specified by:
      hvals in interface RedisSession
      Parameters:
      key - the key
      h - receives array of values
    • hdel

      public void hdel(String key, IntegerResultHandler h, String... fields)
      Description copied from interface: RedisSession
      Deletes hash fields.
      Specified by:
      hdel in interface RedisSession
      Parameters:
      key - the key
      h - receives count of fields deleted
      fields - the field names
    • hexists

      public void hexists(String key, String field, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Checks if a hash field exists.
      Specified by:
      hexists in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      h - receives true if exists
    • hlen

      public void hlen(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the number of fields in a hash.
      Specified by:
      hlen in interface RedisSession
      Parameters:
      key - the key
      h - receives the count
    • hincrby

      public void hincrby(String key, String field, long increment, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Increments a hash field by an integer.
      Specified by:
      hincrby in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      increment - the amount
      h - receives the new value
    • hincrbyfloat

      public void hincrbyfloat(String key, String field, double increment, BulkResultHandler h)
      Description copied from interface: RedisSession
      Increments a hash field by a float.
      Specified by:
      hincrbyfloat in interface RedisSession
      Parameters:
      key - the key
      field - the field name
      increment - the amount
      h - receives the new value as a string
    • lpush

      public void lpush(String key, IntegerResultHandler h, String... values)
      Description copied from interface: RedisSession
      Pushes values to the left (head) of a list.
      Specified by:
      lpush in interface RedisSession
      Parameters:
      key - the key
      h - receives the new list length
      values - the values to push
    • rpush

      public void rpush(String key, IntegerResultHandler h, String... values)
      Description copied from interface: RedisSession
      Pushes values to the right (tail) of a list.
      Specified by:
      rpush in interface RedisSession
      Parameters:
      key - the key
      h - receives the new list length
      values - the values to push
    • lpop

      public void lpop(String key, BulkResultHandler h)
      Description copied from interface: RedisSession
      Pops a value from the left (head) of a list.
      Specified by:
      lpop in interface RedisSession
      Parameters:
      key - the key
      h - receives the value or null if empty
    • rpop

      public void rpop(String key, BulkResultHandler h)
      Description copied from interface: RedisSession
      Pops a value from the right (tail) of a list.
      Specified by:
      rpop in interface RedisSession
      Parameters:
      key - the key
      h - receives the value or null if empty
    • lrange

      public void lrange(String key, int start, int stop, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets a range of elements from a list.
      Specified by:
      lrange in interface RedisSession
      Parameters:
      key - the key
      start - the start index (0-based, negative from end)
      stop - the stop index (inclusive, negative from end)
      h - receives the elements
    • llen

      public void llen(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the length of a list.
      Specified by:
      llen in interface RedisSession
      Parameters:
      key - the key
      h - receives the length
    • lindex

      public void lindex(String key, int index, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets an element by index.
      Specified by:
      lindex in interface RedisSession
      Parameters:
      key - the key
      index - the index (negative from end)
      h - receives the element or null
    • lset

      public void lset(String key, int index, String value, StringResultHandler h)
      Description copied from interface: RedisSession
      Sets an element by index.
      Specified by:
      lset in interface RedisSession
      Parameters:
      key - the key
      index - the index
      value - the new value
      h - receives "OK"
    • ltrim

      public void ltrim(String key, int start, int stop, StringResultHandler h)
      Description copied from interface: RedisSession
      Trims a list to the specified range.
      Specified by:
      ltrim in interface RedisSession
      Parameters:
      key - the key
      start - the start index
      stop - the stop index
      h - receives "OK"
    • lrem

      public void lrem(String key, int count, String value, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Removes elements from a list.
      Specified by:
      lrem in interface RedisSession
      Parameters:
      key - the key
      count - number to remove (0=all, positive=from head, negative=from tail)
      value - the value to remove
      h - receives the count removed
    • blpop

      public void blpop(double timeout, ArrayResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Blocking pop from the left (head) of one or more lists. Blocks until an element is available or the timeout expires.
      Specified by:
      blpop in interface RedisSession
      Parameters:
      timeout - the timeout in seconds (0 = block indefinitely)
      h - receives [key, value] array or null on timeout
      keys - the list keys to pop from
    • brpop

      public void brpop(double timeout, ArrayResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Blocking pop from the right (tail) of one or more lists. Blocks until an element is available or the timeout expires.
      Specified by:
      brpop in interface RedisSession
      Parameters:
      timeout - the timeout in seconds (0 = block indefinitely)
      h - receives [key, value] array or null on timeout
      keys - the list keys to pop from
    • blmove

      public void blmove(String source, String destination, String whereFrom, String whereTo, double timeout, BulkResultHandler h)
      Description copied from interface: RedisSession
      Blocking move of an element from one list to another (Redis 6.2+).
      Specified by:
      blmove in interface RedisSession
      Parameters:
      source - the source list key
      destination - the destination list key
      whereFrom - "LEFT" or "RIGHT"
      whereTo - "LEFT" or "RIGHT"
      timeout - the timeout in seconds (0 = block indefinitely)
      h - receives the moved element or null on timeout
    • sadd

      public void sadd(String key, IntegerResultHandler h, String... members)
      Description copied from interface: RedisSession
      Adds members to a set.
      Specified by:
      sadd in interface RedisSession
      Parameters:
      key - the key
      h - receives count of new members added
      members - the members to add
    • srem

      public void srem(String key, IntegerResultHandler h, String... members)
      Description copied from interface: RedisSession
      Removes members from a set.
      Specified by:
      srem in interface RedisSession
      Parameters:
      key - the key
      h - receives count of members removed
      members - the members to remove
    • smembers

      public void smembers(String key, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets all members of a set.
      Specified by:
      smembers in interface RedisSession
      Parameters:
      key - the key
      h - receives the members
    • sismember

      public void sismember(String key, String member, BooleanResultHandler h)
      Description copied from interface: RedisSession
      Checks if a value is a member of a set.
      Specified by:
      sismember in interface RedisSession
      Parameters:
      key - the key
      member - the member to check
      h - receives true if member exists
    • scard

      public void scard(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the number of members in a set.
      Specified by:
      scard in interface RedisSession
      Parameters:
      key - the key
      h - receives the cardinality
    • spop

      public void spop(String key, BulkResultHandler h)
      Description copied from interface: RedisSession
      Pops a random member from a set.
      Specified by:
      spop in interface RedisSession
      Parameters:
      key - the key
      h - receives the member or null if empty
    • srandmember

      public void srandmember(String key, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets a random member without removing it.
      Specified by:
      srandmember in interface RedisSession
      Parameters:
      key - the key
      h - receives the member or null if empty
    • zadd

      public void zadd(String key, double score, String member, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Adds a member with a score to a sorted set.
      Specified by:
      zadd in interface RedisSession
      Parameters:
      key - the key
      score - the score
      member - the member
      h - receives count of new members added
    • zscore

      public void zscore(String key, String member, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets the score of a member.
      Specified by:
      zscore in interface RedisSession
      Parameters:
      key - the key
      member - the member
      h - receives the score or null if not found
    • zrange

      public void zrange(String key, int start, int stop, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets members in a range by index.
      Specified by:
      zrange in interface RedisSession
      Parameters:
      key - the key
      start - the start index
      stop - the stop index
      h - receives the members
    • zrangeWithScores

      public void zrangeWithScores(String key, int start, int stop, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets members in a range by index with scores.
      Specified by:
      zrangeWithScores in interface RedisSession
      Parameters:
      key - the key
      start - the start index
      stop - the stop index
      h - receives alternating member/score pairs
    • zrevrange

      public void zrevrange(String key, int start, int stop, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Gets members in reverse order by index.
      Specified by:
      zrevrange in interface RedisSession
      Parameters:
      key - the key
      start - the start index
      stop - the stop index
      h - receives the members
    • zrank

      public void zrank(String key, String member, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the rank of a member (0-based, lowest score first).
      Specified by:
      zrank in interface RedisSession
      Parameters:
      key - the key
      member - the member
      h - receives the rank or null if not found
    • zrem

      public void zrem(String key, IntegerResultHandler h, String... members)
      Description copied from interface: RedisSession
      Removes members from a sorted set.
      Specified by:
      zrem in interface RedisSession
      Parameters:
      key - the key
      h - receives count of members removed
      members - the members to remove
    • zcard

      public void zcard(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the number of members in a sorted set.
      Specified by:
      zcard in interface RedisSession
      Parameters:
      key - the key
      h - receives the cardinality
    • zincrby

      public void zincrby(String key, double increment, String member, BulkResultHandler h)
      Description copied from interface: RedisSession
      Increments a member's score.
      Specified by:
      zincrby in interface RedisSession
      Parameters:
      key - the key
      increment - the amount to add
      member - the member
      h - receives the new score
    • subscribe

      public void subscribe(MessageHandler h, String... channels)
      Description copied from interface: RedisSession
      Subscribes to channels.

      After subscribing, the connection enters Pub/Sub mode and can only execute SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING, and QUIT.

      Specified by:
      subscribe in interface RedisSession
      Parameters:
      h - receives messages and subscription confirmations
      channels - the channels to subscribe to
    • psubscribe

      public void psubscribe(MessageHandler h, String... patterns)
      Description copied from interface: RedisSession
      Subscribes to channel patterns.
      Specified by:
      psubscribe in interface RedisSession
      Parameters:
      h - receives messages and subscription confirmations
      patterns - the glob-style patterns to subscribe to
    • unsubscribe

      public void unsubscribe(String... channels)
      Description copied from interface: RedisSession
      Unsubscribes from channels.
      Specified by:
      unsubscribe in interface RedisSession
      Parameters:
      channels - the channels to unsubscribe from (empty = all)
    • punsubscribe

      public void punsubscribe(String... patterns)
      Description copied from interface: RedisSession
      Unsubscribes from patterns.
      Specified by:
      punsubscribe in interface RedisSession
      Parameters:
      patterns - the patterns to unsubscribe from (empty = all)
    • publish

      public void publish(String channel, String message, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Publishes a message to a channel.
      Specified by:
      publish in interface RedisSession
      Parameters:
      channel - the channel
      message - the message
      h - receives the number of subscribers who received the message
    • publish

      public void publish(String channel, byte[] message, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Publishes a binary message to a channel.
      Specified by:
      publish in interface RedisSession
      Parameters:
      channel - the channel
      message - the message bytes
      h - receives the number of subscribers who received the message
    • multi

      public void multi(StringResultHandler h)
      Description copied from interface: RedisSession
      Marks the start of a transaction.

      After MULTI, all commands are queued until EXEC is called.

      Specified by:
      multi in interface RedisSession
      Parameters:
      h - receives "OK"
    • exec

      public void exec(ArrayResultHandler h)
      Description copied from interface: RedisSession
      Executes all queued commands in a transaction.
      Specified by:
      exec in interface RedisSession
      Parameters:
      h - receives array of results, or null if WATCH failed
    • discard

      public void discard(StringResultHandler h)
      Description copied from interface: RedisSession
      Discards all queued commands.
      Specified by:
      discard in interface RedisSession
      Parameters:
      h - receives "OK"
    • watch

      public void watch(StringResultHandler h, String... keys)
      Description copied from interface: RedisSession
      Watches keys for changes (optimistic locking).
      Specified by:
      watch in interface RedisSession
      Parameters:
      h - receives "OK"
      keys - the keys to watch
    • unwatch

      public void unwatch(StringResultHandler h)
      Description copied from interface: RedisSession
      Unwatches all keys.
      Specified by:
      unwatch in interface RedisSession
      Parameters:
      h - receives "OK"
    • eval

      public void eval(String script, int numKeys, String[] keys, String[] args, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Executes a Lua script.
      Specified by:
      eval in interface RedisSession
      Parameters:
      script - the Lua script
      numKeys - the number of keys
      keys - the keys (available as KEYS[1], KEYS[2], etc.)
      args - additional arguments (available as ARGV[1], ARGV[2], etc.)
      h - receives the script result
    • evalsha

      public void evalsha(String sha1, int numKeys, String[] keys, String[] args, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Executes a cached script by SHA1 hash.
      Specified by:
      evalsha in interface RedisSession
      Parameters:
      sha1 - the script SHA1 hash
      numKeys - the number of keys
      keys - the keys
      args - additional arguments
      h - receives the script result
    • xadd

      public void xadd(String key, String id, BulkResultHandler h, String... fieldsAndValues)
      Description copied from interface: RedisSession
      Appends an entry to a stream.
      Specified by:
      xadd in interface RedisSession
      Parameters:
      key - the stream key
      id - the entry ID ("*" for auto-generated)
      h - receives the entry ID
      fieldsAndValues - alternating field names and values
    • xlen

      public void xlen(String key, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Returns the number of entries in a stream.
      Specified by:
      xlen in interface RedisSession
      Parameters:
      key - the stream key
      h - receives the count
    • xrange

      public void xrange(String key, String start, String end, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns a range of entries from a stream.
      Specified by:
      xrange in interface RedisSession
      Parameters:
      key - the stream key
      start - the start ID ("-" for minimum)
      end - the end ID ("+" for maximum)
      h - receives the entries
    • xrange

      public void xrange(String key, String start, String end, int count, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns a range of entries with a count limit.
      Specified by:
      xrange in interface RedisSession
      Parameters:
      key - the stream key
      start - the start ID ("-" for minimum)
      end - the end ID ("+" for maximum)
      count - the maximum number of entries
      h - receives the entries
    • xrevrange

      public void xrevrange(String key, String end, String start, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns a range of entries in reverse order.
      Specified by:
      xrevrange in interface RedisSession
      Parameters:
      key - the stream key
      end - the end ID ("+" for maximum)
      start - the start ID ("-" for minimum)
      h - receives the entries
    • xrevrange

      public void xrevrange(String key, String end, String start, int count, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns a range of entries in reverse order with a count limit.
      Specified by:
      xrevrange in interface RedisSession
      Parameters:
      key - the stream key
      end - the end ID ("+" for maximum)
      start - the start ID ("-" for minimum)
      count - the maximum number of entries
      h - receives the entries
    • xread

      public void xread(int count, long blockMillis, ArrayResultHandler h, String... keysAndIds)
      Description copied from interface: RedisSession
      Reads entries from one or more streams, optionally blocking.
      Specified by:
      xread in interface RedisSession
      Parameters:
      count - the maximum number of entries per stream (0 for default)
      blockMillis - the block timeout in milliseconds (negative to not block)
      h - receives the entries per stream
      keysAndIds - alternating stream keys and IDs
    • xtrim

      public void xtrim(String key, long maxLen, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Trims a stream to approximately the specified length.
      Specified by:
      xtrim in interface RedisSession
      Parameters:
      key - the stream key
      maxLen - the maximum length
      h - receives the number of entries removed
    • xack

      public void xack(String key, String group, IntegerResultHandler h, String... ids)
      Description copied from interface: RedisSession
      Acknowledges one or more stream entries for a consumer group.
      Specified by:
      xack in interface RedisSession
      Parameters:
      key - the stream key
      group - the consumer group name
      h - receives the count of acknowledged entries
      ids - the entry IDs to acknowledge
    • xgroupCreate

      public void xgroupCreate(String key, String group, String id, StringResultHandler h)
      Description copied from interface: RedisSession
      Creates a consumer group for a stream.
      Specified by:
      xgroupCreate in interface RedisSession
      Parameters:
      key - the stream key
      group - the consumer group name
      id - the starting entry ID ("$" for new entries only, "0" for all)
      h - receives "OK"
    • xgroupDestroy

      public void xgroupDestroy(String key, String group, IntegerResultHandler h)
      Description copied from interface: RedisSession
      Deletes a consumer group.
      Specified by:
      xgroupDestroy in interface RedisSession
      Parameters:
      key - the stream key
      group - the consumer group name
      h - receives the result
    • xpending

      public void xpending(String key, String group, ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns the number of pending entries for a consumer group.
      Specified by:
      xpending in interface RedisSession
      Parameters:
      key - the stream key
      group - the consumer group name
      h - receives the pending entry information
    • info

      public void info(BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets server information.
      Specified by:
      info in interface RedisSession
      Parameters:
      h - receives the info string
    • info

      public void info(String section, BulkResultHandler h)
      Description copied from interface: RedisSession
      Gets server information for a specific section.
      Specified by:
      info in interface RedisSession
      Parameters:
      section - the section name
      h - receives the info string
    • dbsize

      public void dbsize(IntegerResultHandler h)
      Description copied from interface: RedisSession
      Gets the number of keys in the current database.
      Specified by:
      dbsize in interface RedisSession
      Parameters:
      h - receives the count
    • flushdb

      public void flushdb(StringResultHandler h)
      Description copied from interface: RedisSession
      Flushes the current database.
      Specified by:
      flushdb in interface RedisSession
      Parameters:
      h - receives "OK"
    • flushall

      public void flushall(StringResultHandler h)
      Description copied from interface: RedisSession
      Flushes all databases.
      Specified by:
      flushall in interface RedisSession
      Parameters:
      h - receives "OK"
    • time

      public void time(ArrayResultHandler h)
      Description copied from interface: RedisSession
      Returns the server time.
      Specified by:
      time in interface RedisSession
      Parameters:
      h - receives array of [unix timestamp seconds, microseconds]
    • command

      public void command(ArrayResultHandler h, String command, String... args)
      Description copied from interface: RedisSession
      Sends a raw command with string arguments.

      Use this for commands not covered by specific methods.

      Specified by:
      command in interface RedisSession
      Parameters:
      h - receives the result
      command - the command name
      args - the arguments
    • command

      public void command(ArrayResultHandler h, String command, byte[]... args)
      Description copied from interface: RedisSession
      Sends a raw command with byte array arguments.
      Specified by:
      command in interface RedisSession
      Parameters:
      h - receives the result
      command - the command name
      args - the arguments as byte arrays