如何使用包含空格的键从Redis获取值? [英] How to get values from Redis using keys which contains spaces?
本文介绍了如何使用包含空格的键从Redis获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用telnet,我输入像这样的命令行命令
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
推荐答案
如果只有telnet(而不是'redis-cli'),则需要使用Redis二进制安全统一协议在键名中使用空格,例如:
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)
有关Redis二进制安全协议的更多信息: http://redis.io/topics/protocol
More information about Redis binary-safe protocol: http://redis.io/topics/protocol
这篇关于如何使用包含空格的键从Redis获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文