无法使用协议规范写入Redis

时间:2014-01-22 15:08:40

标签: bash nosql redis

当我通过端口6379 telnet到我的Redis服务器时,我应该能够使用http://redis.io/topics/protocol中概述的协议规范。相反,我得到无效的批量长度。我在初始* 3(启动协议规范)后放置的任何内容都会抛出此错误。 我在Suse Linux Enterprise 11上使用Bash。

例如:

telnet localhost 6379
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
*3\r\n$5\r\nLPUSH\r\n$4\r\nlogs\r\n$20\r\n"this is some data!"\r\n
-ERR Protocol error: invalid multibulk length
Connection closed by foreign host.

以及甚至:

telnet localhost 6379
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
*3\r\n
-ERR Protocol error: invalid multibulk length
Connection closed by foreign host.

我在Redis 2.6(Redis服务器v = 2.6.13)上应该支持协议规范。 我能做错什么? 提前致谢, 科尔

1 个答案:

答案 0 :(得分:1)

\ r \ n不是由telnet解释的。它们代表回车和换行,它们只是telnet协议的一部分。只需按“Enter”即可从telnet生成它们。

$ telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
*3
$5
LPUSH
$4
logs
$20
"this is some data!"
:1
quit
+OK

我建议使用任何Perl / Python / Ruby / PHP / ...脚本来访问Redis,而不是直接从shell脚本处理Redis协议。