Class LettuceRedisOperations

java.lang.Object
io.github.ravocode.avoonce.redis.LettuceRedisOperations
All Implemented Interfaces:
RedisOperations

public class LettuceRedisOperations extends Object implements RedisOperations
A RedisOperations adapter for the Lettuce client.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LettuceRedisOperations(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> connection)
    Creates a new operations adapter using an existing connection.
    LettuceRedisOperations(io.lettuce.core.RedisClient redisClient)
    Creates a new operations adapter using the provided Lettuce client.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(byte[] key)
    Deletes the specified key.
    byte[]
    get(byte[] key)
    Retrieves the value associated with a key.
    void
    set(byte[] key, byte[] value, long ttlMillis)
    Updates an existing key with a new value and extends its time-to-live.
    boolean
    setIfAbsent(byte[] key, byte[] value, long ttlMillis)
    Atomically sets a key to a value with a time-to-live only if the key does not already exist.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LettuceRedisOperations

      public LettuceRedisOperations(io.lettuce.core.RedisClient redisClient)
      Creates a new operations adapter using the provided Lettuce client. Note: Lettuce connections are thread-safe and designed to be long-lived.
      Parameters:
      redisClient - The configured Lettuce RedisClient.
    • LettuceRedisOperations

      public LettuceRedisOperations(io.lettuce.core.api.StatefulRedisConnection<byte[],byte[]> connection)
      Creates a new operations adapter using an existing connection.
      Parameters:
      connection - An existing StatefulRedisConnection using byte arrays.
  • Method Details

    • setIfAbsent

      public boolean setIfAbsent(byte[] key, byte[] value, long ttlMillis)
      Atomically sets a key to a value with a time-to-live only if the key does not already exist. Equivalent to Redis command: SET key value NX PX ttlMillis
      Specified by:
      setIfAbsent in interface RedisOperations
      Parameters:
      key - The key to set.
      value - The value to store.
      ttlMillis - Time-to-live in milliseconds.
      Returns:
      true if the key was set, false if it already existed.
    • set

      public void set(byte[] key, byte[] value, long ttlMillis)
      Updates an existing key with a new value and extends its time-to-live. Equivalent to Redis command: SET key value XX PX ttlMillis
      Specified by:
      set in interface RedisOperations
      Parameters:
      key - The key to update.
      value - The new value to store.
      ttlMillis - Time-to-live in milliseconds.
    • get

      public byte[] get(byte[] key)
      Retrieves the value associated with a key. Equivalent to Redis command: GET key
      Specified by:
      get in interface RedisOperations
      Parameters:
      key - The key to retrieve.
      Returns:
      The value, or null if the key does not exist.
    • delete

      public void delete(byte[] key)
      Deletes the specified key. Equivalent to Redis command: DEL key
      Specified by:
      delete in interface RedisOperations
      Parameters:
      key - The key to delete.