Class RedissonClientAdapter

java.lang.Object
io.agentscope.extensions.redis.state.redisson.RedissonClientAdapter
All Implemented Interfaces:
RedisClientAdapter

public class RedissonClientAdapter extends Object implements RedisClientAdapter
Adapter for Redisson Redis client.

Redisson provides a comprehensive Redis client that automatically handles different deployment modes through a unified RedissonClient interface.

This adapter supports all Redisson deployment modes:

  • Standalone mode - single Redis instance
  • Cluster mode - Redis Cluster with multiple nodes
  • Sentinel mode - Redis with Sentinel for high availability
  • Master/Slave mode - Redis with master-slave replication

RedissonClient manages connection pooling, thread safety, and mode-specific logic internally, providing a seamless experience across all deployment modes.

Usage Examples:

Standalone Mode:


 // Create standalone configuration
 Config config = new Config();
 config.useSingleServer()
     .setAddress("redis://localhost:6379")
     .setConnectionMinimumIdleSize(5)
     .setConnectionPoolSize(20);

 // Create RedissonClient
 RedissonClient redissonClient = Redisson.create(config);

 // Create adapter
 RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);

 // Use with RedisAgentStateStore
 AgentStateStore stateStore = RedisAgentStateStore.builder()
     .redissonClient(redissonClient)
     .build();
 

Cluster Mode:


 // Create cluster configuration
 Config config = new Config();
 config.useClusterServers()
     .addNodeAddress("redis://localhost:7000", "redis://localhost:7001", "redis://localhost:7002")
     .setScanInterval(2000);

 // Create RedissonClient
 RedissonClient redissonClient = Redisson.create(config);

 // Create adapter
 RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
 

Sentinel Mode:


 // Create sentinel configuration
 Config config = new Config();
 config.useSentinelServers()
     .setMasterName("mymaster")
     .addSentinelAddress("redis://localhost:26379", "redis://localhost:26380")
     .setDatabase(0);

 // Create RedissonClient
 RedissonClient redissonClient = Redisson.create(config);

 // Create adapter
 RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
 

Master/Slave Mode:


 // Create master/slave configuration
 Config config = new Config();
 config.useMasterSlaveServers()
     .setMasterAddress("redis://localhost:6379")
     .addSlaveAddress("redis://localhost:6380", "redis://localhost:6381")
     .setReadMode(ReadMode.SLAVE);

 // Create RedissonClient
 RedissonClient redissonClient = Redisson.create(config);

 // Create adapter
 RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
 
  • Method Details

    • of

      public static RedissonClientAdapter of(org.redisson.api.RedissonClient redissonClient)
      Create adapter from RedissonClient.

      The RedissonClient can be configured for any deployment mode (standalone, cluster, sentinel, master/slave), and the adapter will handle the mode-specific details transparently.

      Parameters:
      redissonClient - the RedissonClient instance
      Returns:
      a new RedissonClientAdapter
    • set

      public void set(String key, String value)
      Description copied from interface: RedisClientAdapter
      Set a string value.
      Specified by:
      set in interface RedisClientAdapter
      Parameters:
      key - the Redis key
      value - the string value
    • get

      public String get(String key)
      Description copied from interface: RedisClientAdapter
      Get a string value.
      Specified by:
      get in interface RedisClientAdapter
      Parameters:
      key - the Redis key
      Returns:
      the string value, or null if not found
    • rightPushList

      public void rightPushList(String key, String value)
      Description copied from interface: RedisClientAdapter
      Append a value to the right end of a list.
      Specified by:
      rightPushList in interface RedisClientAdapter
      Parameters:
      key - the Redis list key
      value - the value to append
    • rangeList

      public List<String> rangeList(String key, long start, long end)
      Description copied from interface: RedisClientAdapter
      Get a range of elements from a list.
      Specified by:
      rangeList in interface RedisClientAdapter
      Parameters:
      key - the Redis list key
      start - the start index (inclusive)
      end - the end index (inclusive, -1 for all elements)
      Returns:
      list of values
    • getListLength

      public long getListLength(String key)
      Description copied from interface: RedisClientAdapter
      Get the length of a list.
      Specified by:
      getListLength in interface RedisClientAdapter
      Parameters:
      key - the Redis list key
      Returns:
      the length of the list
    • deleteKeys

      public void deleteKeys(String... keys)
      Description copied from interface: RedisClientAdapter
      Delete one or more keys.
      Specified by:
      deleteKeys in interface RedisClientAdapter
      Parameters:
      keys - the keys to delete
    • addToSet

      public void addToSet(String key, String member)
      Description copied from interface: RedisClientAdapter
      Add a member to a set.
      Specified by:
      addToSet in interface RedisClientAdapter
      Parameters:
      key - the Redis set key
      member - the member to add
    • getSetMembers

      public Set<String> getSetMembers(String key)
      Description copied from interface: RedisClientAdapter
      Get all members of a set.
      Specified by:
      getSetMembers in interface RedisClientAdapter
      Parameters:
      key - the Redis set key
      Returns:
      set of members
    • getSetSize

      public long getSetSize(String key)
      Description copied from interface: RedisClientAdapter
      Get the number of members in a set.
      Specified by:
      getSetSize in interface RedisClientAdapter
      Parameters:
      key - the Redis set key
      Returns:
      the number of members
    • keyExists

      public boolean keyExists(String key)
      Description copied from interface: RedisClientAdapter
      Check if a key exists.
      Specified by:
      keyExists in interface RedisClientAdapter
      Parameters:
      key - the Redis key
      Returns:
      true if the key exists
    • findKeysByPattern

      public Set<String> findKeysByPattern(String pattern)
      Description copied from interface: RedisClientAdapter
      Find all keys matching a pattern.
      Specified by:
      findKeysByPattern in interface RedisClientAdapter
      Parameters:
      pattern - the key pattern (e.g., "prefix:*")
      Returns:
      set of matching keys
    • evalScript

      public long evalScript(String script, List<String> keys, List<String> args)
      Description copied from interface: RedisClientAdapter
      Execute a Lua script atomically.
      Specified by:
      evalScript in interface RedisClientAdapter
      Parameters:
      script - the Lua script source
      keys - Redis keys passed as KEYS
      args - Redis arguments passed as ARGV
      Returns:
      the script return value as a long
    • close

      public void close()
      Description copied from interface: RedisClientAdapter
      Close the adapter and release resources.
      Specified by:
      close in interface RedisClientAdapter