如何在redis控制台中读取Redis二进制值

How to read Redis binary values in redis console

我在 Redis 条目中存储了一个包含 5 个字节的字节数组。使用客户端库进行写入和读取工作正常且符合预期,但是当我尝试读取 Redis 控制台中的值时,我得到一些我不知道如何解释的内容:

>get keyHere
"\x02\x8e\x8b\x0cb"

有些东西我显然不明白,因为 \x0cb 不是一个字节的十六进制值,而且只有 4 个 \x(我预计 5 个字节是 5 个)。

一头雾水,决定做个实验。我自学了如何设置原始字节;我将条目的值设置为“\x01\x07”并读回。我期望“\x01\x07”,但读取值显示为“\x01\a”。

>set "3" "\x01\x07"
OK
>get 3
"\x01\a" 

我应该如何在 Redis 控制台中读取 Redis 缓存中的条目以查看原始字节?

如果字节不可打印,redis-cli 打印十六进制格式,否则打印 c-escpaped 序列。

because \x0cb is not a hex value for a byte and there are only 4 \x (and I expected 5 for 5 bytes)

前 4 个字节不可打印,因此以十六进制格式打印。最后一个字节是 b,它是可打印的。

I expected "\x01\x07" but the read value is shown as "\x01\a".

\x07 的 c-escaped 序列是 \a,并且是可打印的。

How should I read entries in a Redis cache in the Redis console to see raw bytes?

如果您需要原始字节(可能无法打印),您可以在 运行 redis-cli.

时指定 --raw 选项