如何在 redis-cli 控制台中列出数据?

huangapple go评论69阅读模式
英文:

How to list the data using redis-cli console?

问题

我能够通过我的 RESTful API 方法调用添加和查看键值对。
如何在 redis-cli 控制台中列出数据?

但是在添加了键值对之后,当我尝试使用 redis-cli 控制台列出/查看它们时,没有列出任何值。
如何在 redis-cli 控制台中列出数据?

正如您所注意到的,在控制台中,**keys *** 命令(通过浏览器添加新键值后)列出了一些垃圾值,但是当我尝试检索键时,它显示为空。

这可能是什么原因?
如何在控制台中正确列出这些值?

同时附上 RESTful API 方法的定义:
如何在 redis-cli 控制台中列出数据?

英文:

I am able to add & view the key value pairs through my restful API method invocations.
如何在 redis-cli 控制台中列出数据?

But after adding the key value pairs, when I try to list/ view them using redis-cli console, it is not listing any values.
如何在 redis-cli 控制台中列出数据?

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?

also attaching the restful api method definitions:
如何在 redis-cli 控制台中列出数据?

答案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 键的值。

如何在 redis-cli 控制台中列出数据?

英文:

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.

如何在 redis-cli 控制台中列出数据?

huangapple
  • 本文由 发表于 2020年8月18日 20:35:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/63468736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定