python - Mass insert with Redis fails with strange errors -
i playing redis mass import using pipe , have following python script:
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()
it produces:
$ python redis_test.py *4 $4 hset $6 myhash $7 myfield $7 myvalue
output of piping:
$ python redis_test.py | redis-cli -h rnode -n 5 --pipe --pipe-timeout 1 data transferred. waiting last reply... err unknown command '2' err unknown command '$4' err wrong number of arguments 'echo' command err unknown command '$20' err unknown command '�˛�Ʃa\m���pm��x�[�' no replies 1 seconds: exiting. errors: 6, replies: 6
although getting populate db, know what's causing errors?
rnode:6379[5]> keys * 1) "myhash" rnode:6379[5]> hgetall myhash 1) "myfield" 2) "myvalue"
answer own question: didn't know needed final crlf, hence this:
print mydata.rstrip()
became:
print mydata
result:
$ python redis_test.py | redis-cli -h rnode -n 5 --pipe --pipe-timeout 10 data transferred. waiting last reply... last reply received server. errors: 0, replies: 1
Comments
Post a Comment