I am using io.quarkus.redis.client.RedisClient
which inside use Vert.x for a Redis Client in Java. When I use HSCAN method it return a list of key and values in differents rows like this:
The keys are 0,2,4… and the values are the JSONs. Is there a way to obtain a Map<key,value> instead of a list with a key and values mix in a elegant/clean way?
2
Answers
You will need to iterate over the Response in order to get the map.
Here is an example for Map<String, String> with for loop:
Here is the same example but using java lambdas:
For your case with json you can just change the transformation function from
.toString()
to something that suits your need.Edit 1:
As HSCAN returns array as defined:
There is not a simple solution to create a map but this is what I recommend:
You can do it with a simple
for
In Kotlin you can use a more elegant solution but I think this one works