我正在使用管道使用Redis批量导入,并使用以下Python脚本:
mydata = ""
mydata += "*4\r\n$4\r\nHSET\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n$%d\r\n%s\r\n" % (len('myhash'), 'myhash', len('myfield'), 'myfield', len('myvalue'), 'myvalue')
print mydata.rstrip()
它产生:
$ python redis_test.py
*4
$4
HSET
$6
myhash
$7
myfield
$7
myvalue
管道输出:
$ python redis_test.py | redis-cli -h rnode -n 5 --pipe --pipe-timeout 1
All data transferred. Waiting for the last reply...
ERR unknown command '2'
ERR unknown command '$4'
ERR wrong number of arguments for 'echo' command
ERR unknown command '$20'
ERR unknown command '�˛�ƩA\m���pm��X�[�'
No replies for 1 seconds: exiting.
errors: 6, replies: 6
虽然我要填充数据库,但我想知道是什么导致了这些错误?
rnode:6379[5]> keys *
1) "myhash"
rnode:6379[5]> hgetall myhash
1) "myfield"
2) "myvalue"
答案 0 :(得分:0)
回答我自己的问题:我不知道它需要最终的CRLF,因此:
print mydata.rstrip()
变成了:
print mydata
结果:
$ python redis_test.py | redis-cli -h rnode -n 5 --pipe --pipe-timeout 10
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1