小编典典

如何使用包含空格的键从Redis获取值?

redis

我使用telnet输入这样的命令行命令

get field with spaces
get "field with spaces"
get 'field with spaces'

所有这三个返回相同的错误。

-ERR wrong number of arguments for 'get' command

阅读 339

收藏
2020-06-20

共1个答案

小编典典

如果只有telnet(而不是’redis-cli’),则需要使用Redis二进制安全统一协议在键名中使用空格,例如:

telnet localhost 6379
*2
$3
GET
$17
field with spaces
hello (this is Redis answer if "field with spaces" contains value "hello")

Explanation:
*2 = Number of arguments (first arg is "GET" and second is "field with spaces")
$3 = length of first argument ("GET" contains 3 bytes)
$17 = length of second argument ("field with spaces" contains 17 bytes)

有关Redis二进制安全协议的更多信息:http :
//redis.io/topics/protocol

2020-06-20