Class RedisFeatureStore

java.lang.Object
cloud.opencode.base.feature.store.RedisFeatureStore
All Implemented Interfaces:
FeatureStore

public class RedisFeatureStore extends Object implements FeatureStore
Redis Feature Store Redis功能存储

Distributed storage using Redis (requires external Redis client).

使用Redis的分布式存储(需要外部Redis客户端)。

Features | 主要功能:

  • Distributed storage - 分布式存储
  • TTL support - TTL支持
  • Cluster support - 集群支持

Usage Examples | 使用示例:

// With custom Redis client
RedisFeatureStore store = new RedisFeatureStore(
    "feature:",
    Duration.ofHours(1),
    (key, feature) -> redisClient.set(key, serialize(feature)),
    key -> deserialize(redisClient.get(key)),
    () -> redisClient.keys("feature:*").stream()
        .map(k -> deserialize(redisClient.get(k)))
        .toList(),
    key -> redisClient.del(key),
    () -> redisClient.keys("feature:*").forEach(redisClient::del)
);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • RedisFeatureStore

      public RedisFeatureStore(String keyPrefix, Duration ttl, BiConsumer<String,Feature> setter, Function<String,Feature> getter, Supplier<List<Feature>> listAll, Function<String,Boolean> deleter, Runnable clearer)
      Create Redis store with custom operations 使用自定义操作创建Redis存储
      Parameters:
      keyPrefix - the key prefix | 键前缀
      ttl - the TTL for features | 功能的TTL
      setter - function to set feature | 设置功能的函数
      getter - function to get feature | 获取功能的函数
      listAll - function to list all features | 列出所有功能的函数
      deleter - function to delete feature | 删除功能的函数
      clearer - function to clear all | 清除所有的函数
  • Method Details

    • save

      public void save(Feature feature)
      Description copied from interface: FeatureStore
      Save a feature 保存功能
      Specified by:
      save in interface FeatureStore
      Parameters:
      feature - the feature to save | 要保存的功能
    • find

      public Optional<Feature> find(String key)
      Description copied from interface: FeatureStore
      Find a feature by key 根据键查找功能
      Specified by:
      find in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      optional containing feature if found | 如果找到则包含功能的Optional
    • findAll

      public List<Feature> findAll()
      Description copied from interface: FeatureStore
      Find all features 查找所有功能
      Specified by:
      findAll in interface FeatureStore
      Returns:
      list of all features | 所有功能的列表
    • delete

      public boolean delete(String key)
      Description copied from interface: FeatureStore
      Delete a feature 删除功能
      Specified by:
      delete in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      true if deleted | 如果删除成功返回true
    • clear

      public void clear()
      Description copied from interface: FeatureStore
      Clear all features 清除所有功能
      Specified by:
      clear in interface FeatureStore
    • getKeyPrefix

      public String getKeyPrefix()
      Get the key prefix 获取键前缀
      Returns:
      key prefix | 键前缀
    • getTtl

      public Duration getTtl()
      Get the TTL 获取TTL
      Returns:
      TTL | TTL