3

I am using Spring Data Redis and using hash operations to save the Map<String, Long> as a hash in Redis.

Suppose hash is "some hash", hashkey is "unique key" & hash value is "Map<String, Long>".

 Map<String,Long > data= new HashMap<>());
 data.put("k", 21474836470); //value = Integer.MAX*10
 hashOperations.put("some hash", "unique key", data);
 Map<String,Integer> result = hashOperations.get( "some hash", "unique key");

The problem here is the result is Map<String, Integer> instead of Map<String, Long>.

When the value in a map stored in Redis is greater than Integer.MAX, then I will get the wrong value in the result map.

enter image description here

I am able to save 10 times of Integer.MAX value through Redis-CLI. Seems the range of Redis integer is different from Java Integer.

Through Redis CLI I can get a large value of an integer, but on Java, the return type is Java integer, which will not work for Long value.

I am using Jackson2JsonRedisSerializer as a hash value and value serializer.

How do I fix this?

asked May 14, 2021 at 2:35
0

1 Answer 1

2

I tested with a value greater than Integer.MAX and Spring is able to convert it into a Long value.

For values less than Integer.MAX it is converting to Integer. For values greater than Integer.MAX it is converting to Long.

answered May 14, 2021 at 10:04
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.