{"record":{"id":"9b7d7379e09d0a3e","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-store-item-in-redis-like-storage","errorCode":null,"errorMessage":"Failed to store item in Redis-like storage","messagePattern":"Failed to store item in Redis-like storage","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/RedisStore.java","lineNumber":87,"sourceCode":"\tpublic RedisStore(String keyPrefix) {\n\t\tthis.redisLikeStorage = new HashMap<>();\n\t\tthis.keyPrefix = keyPrefix;\n\t\tthis.objectMapper = new ObjectMapper();\n\t\tthis.objectMapper.findAndRegisterModules();\n\t}\n\n\t@Override\n\tpublic void putItem(StoreItem item) {\n\t\tvalidatePutItem(item);\n\n\t\tlock.writeLock().lock();\n\t\ttry {\n\t\t\tString redisKey = createRedisKey(item.getNamespace(), item.getKey());\n\t\t\tString itemJson = objectMapper.writeValueAsString(item);\n\t\t\tredisLikeStorage.put(redisKey, itemJson);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to store item in Redis-like storage\", e);\n\t\t}\n\t\tfinally {\n\t\t\tlock.writeLock().unlock();\n\t\t}\n\t}\n\n\t@Override\n\tpublic Optional<StoreItem> getItem(List<String> namespace, String key) {\n\t\tvalidateGetItem(namespace, key);\n\n\t\tlock.readLock().lock();\n\t\ttry {\n\t\t\tString redisKey = createRedisKey(namespace, key);\n\t\t\tString value = redisLikeStorage.get(redisKey);\n\n\t\t\tif (value == null) {\n\t\t\t\treturn Optional.empty();\n\t\t\t}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/RedisStore.java#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Redis connection misconfiguration, expired/missing credentials, Redis timeout under load, custom ObjectMapper registered serializers that fail on StoreItem fields, or null key/namespace values.","solutions":["Check the wrapped cause (e.getCause()) — most often a Redis connection/timeout exception; fix connectivity or credentials first.","Verify the Redis-like storage client is started and reachable before calling putItem.","Ensure StoreItem fields are JSON-serializable and the ObjectMapper has correct module registration.","Retry putItem after transient connection failures; consider a RetryTemplate/backoff."],"exampleFix":"// before\nstore.putItem(item); // fails on transient Redis outage\n// after\ntry {\n    store.putItem(item);\n} catch (RuntimeException e) {\n    logger.warn(\"Redis put failed, retrying\", e.getCause());\n    retryTemplate.execute(ctx -> { store.putItem(item); return null; });\n}","handlingStrategy":"try-catch","validationCode":"if (item == null || item.getKey() == null) throw new IllegalArgumentException(\"StoreItem and key required\");\n// also verify connectivity beforehand if the client exposes a health/ping op","typeGuard":null,"tryCatchPattern":"try {\n    store.putItem(item);\n} catch (RuntimeException e) {\n    Throwable root = e.getCause();\n    logger.error(\"Redis put failed, root cause: {}\", root == null ? e : root.getMessage(), e);\n    throw e; // or enqueue for retry\n}","preventionTips":["Always log the wrapped cause — it names the real failure (connection vs serialization).","Health-check the Redis client at startup.","Keep ObjectMapper configuration symmetric with reads.","Use retry with backoff for transient Redis errors."],"tags":["redis","storage","serialization"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}