We are using Lettuce java client to connect to AWS Elasticache (Valkey engine, Serverless, version 8.0) from Java springboot application (JDK 17 & springboot version 3.2.5)
Below is the method where I am trying to write multiple keys into elasticache using jsonMSet().
public void setJsonObjects(List<Details> details, long ttl) {
cacheConnectionPool.thenCompose(connectionPool -> {
try {
StatefulRedisConnection<String, String> connection = connectionPool.acquire().get();
RedisAsyncCommands<String, String> async = connection.async();
async.jsonMSet(createJsonMsetArgs(details, async));
return async.exec().whenComplete((s, throwable) -> connectionPool.release(connection));
} catch (Exception e) {
log.warn("Exception while writing to Cache: {}", e.getMessage());
return null;
}
});
}
public List<JsonMsetArgs<String, String>> createJsonMsetArgs(List<Details> details,
RedisAsyncCommands<String, String> async) {
List<JsonMsetArgs<String, String>> msetList = new ArrayList<>();
if (details != null && !details.isEmpty()) {
details.forEach(detail -> {
JsonMsetArgs<String, String> msetArg = new JsonMsetArgs<String, String>(
String.format(KEY_FORMAT, detail.getId()),
JsonPath.ROOT_PATH,
async.getJsonParser().fromObject(detail));
msetList.add(msetArg);
});
}
return msetList;
}
Code executes fine without any errors or warnings. But nothing is being written into elasticache. The new cache Keys are not appearing in cache.
Could you please advise what is going wrong here ?
Regards, Alex