Module bus.cache

Class RedisClusterCache<K,V>

java.lang.Object
org.miaixz.bus.cache.metric.RedisClusterCache<K,V>
Type Parameters:
K - 键类型
V - 值类型
All Implemented Interfaces:
CacheX<K,V>

public class RedisClusterCache<K,V> extends Object implements CacheX<K,V>
Redis 集群缓存支持

基于Jedis客户端实现的Redis集群缓存接口,提供分布式缓存功能。 支持序列化和反序列化操作,并提供批量读写操作。 使用@PreDestroy注解确保资源正确释放。

Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • RedisClusterCache

      public RedisClusterCache(redis.clients.jedis.JedisCluster jedisCluster)
      构造方法

      使用指定的Jedis集群客户端和默认的Hessian2序列化器创建缓存实例

      Parameters:
      jedisCluster - Jedis集群客户端
    • RedisClusterCache

      public RedisClusterCache(redis.clients.jedis.JedisCluster jedisCluster, BaseSerializer serializer)
      构造方法

      使用指定的Jedis集群客户端和序列化器创建缓存实例

      Parameters:
      jedisCluster - Jedis集群客户端
      serializer - 序列化器
  • Method Details

    • read

      public V read(K key)
      从缓存中读取单个值
      Specified by:
      read in interface CacheX<K,V>
      Parameters:
      key - 键
      Returns:
      值,如果不存在则返回null
    • write

      public void write(K key, V value, long expire)
      向缓存中写入单个键值对
      Specified by:
      write in interface CacheX<K,V>
      Parameters:
      key - 键
      value - 值
      expire - 过期时间(毫秒)
    • read

      public Map<K,V> read(Collection<K> keys)
      从缓存中批量读取值
      Specified by:
      read in interface CacheX<K,V>
      Parameters:
      keys - 键集合
      Returns:
      键值映射
    • write

      public void write(Map<K,V> keyValueMap, long expire)
      向缓存中批量写入键值对
      Specified by:
      write in interface CacheX<K,V>
      Parameters:
      keyValueMap - 键值映射
      expire - 过期时间(毫秒)
    • remove

      public void remove(K... keys)
      从缓存中移除指定的键
      Specified by:
      remove in interface CacheX<K,V>
      Parameters:
      keys - 要移除的键
    • clear

      public void clear()
      清空缓存
      Specified by:
      clear in interface CacheX<K,V>
    • tearDown

      @PreDestroy public void tearDown()
      销毁方法

      使用@PreDestroy注解,在Bean销毁时关闭Jedis集群连接