java - Lettuce: AWS Elasticache: JSON MGET behaviour - Stack Overflow

We are using Lettuce java client to connect to AWS Elasticache (Valkey engine, Serverless, version 8.0)

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 read multiple keys from elasticache using jsonMGet().

public List<JsonValue> readMultipleKeys(List<String> keys) {

        RedisAsyncCommands<String, String> async = null;
        try {
            async = redisCacheClient.connect().async();
            return async.jsonMGet(JsonPath.ROOT_PATH, keys.toArray(new String[0])).get();
        } catch (Exception e) {
            log.error("Exception while reading multiple keys from Cache: " + e.getMessage());
            return null;
        }
    }

Everything works perfectly fine as long as all the keys from the input list are present in Cache. But if any key (lets say 1 out of 100 input keys) doesn't exist in cache, it is throwing below error and not returning any other values.

Exception while reading from Cache: java.lang.NullPointerException: Cannot invoke "java.nio.ByteBuffer.remaining()" because "bytes" is null

I want the method to return all the keys that are PRESENT in cache and ignore the keys that doesn't exist.

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 read multiple keys from elasticache using jsonMGet().

public List<JsonValue> readMultipleKeys(List<String> keys) {

        RedisAsyncCommands<String, String> async = null;
        try {
            async = redisCacheClient.connect().async();
            return async.jsonMGet(JsonPath.ROOT_PATH, keys.toArray(new String[0])).get();
        } catch (Exception e) {
            log.error("Exception while reading multiple keys from Cache: " + e.getMessage());
            return null;
        }
    }

Everything works perfectly fine as long as all the keys from the input list are present in Cache. But if any key (lets say 1 out of 100 input keys) doesn't exist in cache, it is throwing below error and not returning any other values.

Exception while reading from Cache: java.lang.NullPointerException: Cannot invoke "java.nio.ByteBuffer.remaining()" because "bytes" is null

I want the method to return all the keys that are PRESENT in cache and ignore the keys that doesn't exist.

Share Improve this question edited yesterday desertnaut 60.5k32 gold badges155 silver badges181 bronze badges asked yesterday alexalex 1771 gold badge4 silver badges21 bronze badges 1
  • Which version of the Lettuce driver are you using? A similar issue was addressed with this issue in the 6.5.5 release, see github/redis/lettuce/issues/3196 – Tihomir Mateev Commented 7 hours ago
Add a comment  | 

2 Answers 2

Reset to default 1

EDIT: This seems to be addressed in Lettuce 6.5.5 and later

A NullPointerException is almost certainly a bug.

I've taken the liberty to create one in the GitHub tracker for you: https://github/redis/lettuce/issues/3241

I suggest we continue the conversation there.

Have you tried using other client libraries? Valkey-Glide Java supports JSON. See:
https://github/valkey-io/valkey-glide/tree/main/java
https://github/valkey-io/valkey-glide/wiki/General-Concepts#modules-api

Disclaimer: I'm a Valkey-Glide maintainer and would be happy to help if you open an issue!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743777683a4505533.html

相关推荐

  • java - Lettuce: AWS Elasticache: JSON MGET behaviour - Stack Overflow

    We are using Lettuce java client to connect to AWS Elasticache (Valkey engine, Serverless, version 8.0)

    7天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信