alibaba/spring-ai-alibaba · error · RuntimeException

Failed to store item in Redis-like storage

Error message

Failed to store item in Redis-like storage

What it means

RedisStore.putItem serializes a StoreItem to JSON and writes it to the backing Redis-like storage under a namespace-qualified key. Any failure during key creation, JSON serialization, or the storage put is wrapped in this RuntimeException (with the original cause attached) while releasing the write lock in a finally block.

Source

Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/RedisStore.java:87

	public RedisStore(String keyPrefix) {
		this.redisLikeStorage = new HashMap<>();
		this.keyPrefix = keyPrefix;
		this.objectMapper = new ObjectMapper();
		this.objectMapper.findAndRegisterModules();
	}

	@Override
	public void putItem(StoreItem item) {
		validatePutItem(item);

		lock.writeLock().lock();
		try {
			String redisKey = createRedisKey(item.getNamespace(), item.getKey());
			String itemJson = objectMapper.writeValueAsString(item);
			redisLikeStorage.put(redisKey, itemJson);
		}
		catch (Exception e) {
			throw new RuntimeException("Failed to store item in Redis-like storage", e);
		}
		finally {
			lock.writeLock().unlock();
		}
	}

	@Override
	public Optional<StoreItem> getItem(List<String> namespace, String key) {
		validateGetItem(namespace, key);

		lock.readLock().lock();
		try {
			String redisKey = createRedisKey(namespace, key);
			String value = redisLikeStorage.get(redisKey);

			if (value == null) {
				return Optional.empty();
			}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Check the wrapped cause (e.getCause()) — most often a Redis connection/timeout exception; fix connectivity or credentials first.
  2. Verify the Redis-like storage client is started and reachable before calling putItem.
  3. Ensure StoreItem fields are JSON-serializable and the ObjectMapper has correct module registration.
  4. Retry putItem after transient connection failures; consider a RetryTemplate/backoff.

Example fix

// before
store.putItem(item); // fails on transient Redis outage
// after
try {
    store.putItem(item);
} catch (RuntimeException e) {
    logger.warn("Redis put failed, retrying", e.getCause());
    retryTemplate.execute(ctx -> { store.putItem(item); return null; });
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (item == null || item.getKey() == null) throw new IllegalArgumentException("StoreItem and key required");
// also verify connectivity beforehand if the client exposes a health/ping op

Try / catch

try {
    store.putItem(item);
} catch (RuntimeException e) {
    Throwable root = e.getCause();
    logger.error("Redis put failed, root cause: {}", root == null ? e : root.getMessage(), e);
    throw e; // or enqueue for retry
}

Prevention

When it happens

Trigger: Calling RedisStore.putItem(...) when the Redis-like storage client is down/unreachable, the serialized StoreItem is not valid JSON (bad codec/config on the ObjectMapper), or createRedisKey produces an invalid key.

Common situations: Redis connection misconfiguration, expired/missing credentials, Redis timeout under load, custom ObjectMapper registered serializers that fail on StoreItem fields, or null key/namespace values.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/9b7d7379e09d0a3e. Report an issue: GitHub.