简体   繁体   English

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

[英]How to read Redis binary values in redis console

I store a byte array with 5 bytes in a Redis entry.我在 Redis 条目中存储了一个包含 5 个字节的字节数组。 Writing and reading using a client library works and expected, but when I try to read the value in a Redis console I get something I don't know how to interpret:使用客户端库进行写入和读取工作并符合预期,但是当我尝试读取 Redis 控制台中的值时,我得到一些我不知道如何解释的信息:

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

There is something I clearly don't understand because \x0cb is not a hex value for a byte and there are only 4 \x (and I expected 5 for 5 bytes).有些东西我显然不明白,因为\x0cb不是一个字节的十六进制值,而且只有 4 个\x (我预计 5 个字节是 5 个)。

Confused, I decided to performed an experiment.困惑,我决定进行一个实验。 I educated myself about how to set raw bytes;我自学了如何设置原始字节; I set an entry's value to "\x01\x07" and read it back.我将条目的值设置为“\x01\x07”并读回。 I expected "\x01\x07" but the read value is shown as "\x01\a".我期望“\x01\x07”,但读取值显示为“\x01\a”。

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

How should I read entries in a Redis cache in the Redis console to see raw bytes?我应该如何读取 Redis 控制台中的 Redis 缓存中的条目以查看原始字节?

If the byte is not printable, redis-cli prints the hex format, otherwise, it prints the c-escpaped sequence.如果字节不可打印,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)因为 \x0cb 不是一个字节的十六进制值并且只有 4 \x (我预计 5 个字节为 5 个)

The first 4 bytes are not printable, so they are printed as hex format.前 4 个字节不可打印,因此以十六进制格式打印。 The last byte is the b , which is printable.最后一个字节是b ,它是可打印的。

I expected "\x01\x07" but the read value is shown as "\x01\a".我期望“\x01\x07”,但读取值显示为“\x01\a”。

\x07 's c-escaped sequence is \a , and is printable. \x07的 c 转义序列是\a ,并且是可打印的。

How should I read entries in a Redis cache in the Redis console to see raw bytes?我应该如何读取 Redis 控制台中的 Redis 缓存中的条目以查看原始字节?

If you need the raw bytes (which might not be printable), you can specify the --raw option when running redis-cli.如果您需要原始字节(可能无法打印),您可以在运行 redis-cli 时指定--raw选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM