Class RedisFeatureStore
java.lang.Object
cloud.opencode.base.feature.store.RedisFeatureStore
- All Implemented Interfaces:
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 | 功能的TTLsetter- 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
Description copied from interface:FeatureStoreSave a feature 保存功能- Specified by:
savein interfaceFeatureStore- Parameters:
feature- the feature to save | 要保存的功能
-
find
Description copied from interface:FeatureStoreFind a feature by key 根据键查找功能- Specified by:
findin interfaceFeatureStore- Parameters:
key- the feature key | 功能键- Returns:
- optional containing feature if found | 如果找到则包含功能的Optional
-
findAll
Description copied from interface:FeatureStoreFind all features 查找所有功能- Specified by:
findAllin interfaceFeatureStore- Returns:
- list of all features | 所有功能的列表
-
delete
Description copied from interface:FeatureStoreDelete a feature 删除功能- Specified by:
deletein interfaceFeatureStore- Parameters:
key- the feature key | 功能键- Returns:
- true if deleted | 如果删除成功返回true
-
clear
public void clear()Description copied from interface:FeatureStoreClear all features 清除所有功能- Specified by:
clearin interfaceFeatureStore
-
getKeyPrefix
-
getTtl
-