如何将 HSCAN 响应映射到 Map使用 Vert.x Redis
我正在使用 io.quarkus.redis.client.RedisClient ,其中使用 Vert.x 用于 Java 中的 Redis 客户端。当我使用 HSCAN 方法时,它会返回不同行中的键和值列表,如下所示:
键是 0,2,4...,值是 JSON。有没有办法获取Map
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以用一个简单的
for
来做到这一点在 Kotlin 中你可以使用一个更优雅的解决方案,但我认为这个可行
You can do it with a simple
for
In Kotlin you can use a more elegant solution but I think this one works
您将需要迭代响应才能获取地图。
这是 Map的示例使用 for 循环:
这是相同的示例,但使用 java lambdas:
对于 json 的情况,您只需将转换函数从
.toString()
更改为适合您需要的东西。编辑 1:
当 HSCAN 返回定义的数组时:
创建地图没有一个简单的解决方案,但这是我推荐的:
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: