Class RedisStore
- All Implemented Interfaces:
io.agentscope.harness.agent.filesystem.remote.store.BaseStore
BaseStore implementation.
Key layout
For each item with namespace [a, b, c] and key k, two Redis keys are used:
- Item hash
<prefix>item:<ns>\0<k>— a Redis hash with fieldsvalue(JSON-encodedMap<String,Object>) andversion(a stringified long). - Namespace index
<prefix>idx:<ns>— a sorted set (all scores0) holding everykwritten under that exact namespace, enabling lexicographicsearch(java.util.List<java.lang.String>, int, int)viaZRANGEBYLEXwithout scanning the keyspace.
<ns> is the namespace components joined with "\0".
Concurrency
put(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>) and putIfVersion(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, long) both run as a single Lua EVAL, making the
version read + hash write + index update one atomic Redis operation. This makes
putIfVersion(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, long) safe to use as a distributed compare-and-swap primitive across multiple
processes sharing the same Redis instance.
search(java.util.List<java.lang.String>, int, int) is not in the same transaction as put(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>): index members may
temporarily refer to an item whose hash has not yet been written (window between ZADD
and HSET, which is closed by the Lua atomicity above) or to an item that was
concurrently deleted. The implementation tolerates the latter by skipping missing items.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault Redis key prefix; pick something distinctive enough not to collide with other apps. -
Constructor Summary
ConstructorsConstructorDescriptionRedisStore(redis.clients.jedis.UnifiedJedis jedis) Creates a Redis-backed store with the default key prefix.RedisStore(redis.clients.jedis.UnifiedJedis jedis, String keyPrefix) Creates a Redis-backed store.RedisStore(redis.clients.jedis.UnifiedJedis jedis, String keyPrefix, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a Redis-backed store with a custom JSON mapper. -
Method Summary
Modifier and TypeMethodDescriptionvoidio.agentscope.harness.agent.filesystem.remote.store.StoreItemvoidbooleanList<io.agentscope.harness.agent.filesystem.remote.store.StoreItem>
-
Field Details
-
DEFAULT_KEY_PREFIX
Default Redis key prefix; pick something distinctive enough not to collide with other apps.- See Also:
-
-
Constructor Details
-
RedisStore
public RedisStore(redis.clients.jedis.UnifiedJedis jedis) Creates a Redis-backed store with the default key prefix.- Parameters:
jedis- initialized Jedis client; must not benull
-
RedisStore
Creates a Redis-backed store.- Parameters:
jedis- initialized Jedis client; must not benullkeyPrefix- Redis key prefix; trailing":"is added if absent. If blank, the default is used.
-
RedisStore
public RedisStore(redis.clients.jedis.UnifiedJedis jedis, String keyPrefix, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a Redis-backed store with a custom JSON mapper.- Parameters:
jedis- initialized Jedis client; must not benullkeyPrefix- Redis key prefix; trailing":"is added if absentobjectMapper- Jackson mapper used to serialize / deserialize item values
-
-
Method Details
-
get
public io.agentscope.harness.agent.filesystem.remote.store.StoreItem get(List<String> namespace, String key) - Specified by:
getin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
put
- Specified by:
putin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
putIfVersion
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) - Specified by:
putIfVersionin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
search
public List<io.agentscope.harness.agent.filesystem.remote.store.StoreItem> search(List<String> namespace, int limit, int offset) - Specified by:
searchin interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-
delete
- Specified by:
deletein interfaceio.agentscope.harness.agent.filesystem.remote.store.BaseStore
-