英文:
How to list the data using redis-cli console?
问题
我能够通过我的 RESTful API 方法调用添加和查看键值对。
但是在添加了键值对之后,当我尝试使用 redis-cli 控制台列出/查看它们时,没有列出任何值。
正如您所注意到的,在控制台中,**keys *** 命令(通过浏览器添加新键值后)列出了一些垃圾值,但是当我尝试检索键时,它显示为空。
这可能是什么原因?
如何在控制台中正确列出这些值?
英文:
I am able to add & view the key value pairs through my restful API method invocations.
But after adding the key value pairs, when I try to list/ view them using redis-cli console, it is not listing any values.
As you can notice, in the console, it is listing some junk values for the **keys *** command (after adding new key/value via browser), but when I try to retrieve the key, it is showing up as empty.
What could be the reason for this?
How to list the values properly in the console?
答案1
得分: 5
你在 KEYS *
输出中看到的值是 Java 序列化字符串 user
。
前两个字节 \xac\xed
(十六进制:0xACED)是 STREAM_MAGIC
常量。
接下来的两个字节 \x00\x05
(十六进制:0x0005)是 STREAM_VERSION
,即序列化协议的版本。
接下来的字节 t
为 0x74,表示是一个字符串对象(TC_STRING
)。
最后的 \x00\x04
是字符串的长度。
这个协议在《对象序列化流协议》中有描述,在 6.4.2 终端符号和常量。
你可能需要检查一下你的代码,看看为什么字符串在到达 Redis 之前会被 Java 序列化。可能是因为截图中出现了 h:
。
同时,你可以执行 GET "\xac\xed\x00\x05t\x00\x04user"
来检查你的 user
键的值。
英文:
The value you're seeing in the output of KEYS *
is the java-serialized string user
.
The first two bytes \xac\xed
(hex: 0xACED) is the STREAM_MAGIC
constant.
The next two bytes \x00\x05
(hex: 0x0005) is the STREAM_VERSION
, version of the serialization protocol.
The next byte, t
is 0x74 = TC_STRING
meaning is a string object.
Finally \x00\x04
is the length of the string.
This protocol is described in the Object Serialization Stream Protocol, in 6.4.2 Terminal Symbols and Constants
You probably want to review your code as to why are the strings being java-serialized before reaching Redis. Probably it is because of the h:
that shows in the screenshot.
On the meantime, you can do GET "\xac\xed\x00\x05t\x00\x04user"
to inspect the value of your user
key.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论