melo/perl-redis — pull request #49 by iafan (2013-07-09 14:48:35+00:00)
Title: Improve pipelined mode

https://github.com/melo/perl-redis/pull/21 , while restoring the operability of this library under Windows, seems to have introduced an issue with the pipelined mode. Currently, even when in pipelined mode, the commands are sent to the socket one by one, and between each sending, the call to __try_read_sock() is performed. This looks like a mixed use of buffered/unbuffered IO which is potentially dangerous. And indeed, it somehow breaks the pipe, and Redis receives some odd sequences from Redis that it can't parse.

I changed the pipelined mode behavior to just accumulate raw commands in a buffer, and when wait_all_responses() is called, this buffer is sent through the pipe at once. This not only fixed the pipelined mode, but also gave a significant speed-up in my tests, where I inserted 20-30K commands at once.

Curretnly this works as before, where any call with the provided callback triggers the pipelined mode. But one can trigger this mode explicitly by saying `$redis->{accumulate_commands} = 1;`