How to get values from Redis using keys which cont

2019-06-18 23:49发布

Using telnet I type in command line commands like this

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

And all this three return same error.

-ERR wrong number of arguments for 'get' command

标签: redis key
3条回答
女痞
2楼-- · 2019-06-19 00:20

If you only have telnet (and not 'redis-cli'), then you need to use the Redis binary-safe unified protocol to use spaces in key names, for example:

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)

More information about Redis binary-safe protocol: http://redis.io/topics/protocol

查看更多
Luminary・发光体
3楼-- · 2019-06-19 00:26

What version of redis are you using? It works fine for me on 2.2.2 using double quotes

root@this:~# redis-cli
redis> set "test space" hello
OK
redis> get "test space"
"hello"
redis> get 'test space'
(error) ERR wrong number of arguments for 'get' command
redis> 
查看更多
家丑人穷心不美
4楼-- · 2019-06-19 00:27

get "field\ with\ spaces"

that worked for me.

查看更多
登录 后发表回答