antirez/redis — pull request #1232 by catwell (2013-08-06 00:48:31+00:00)
Title: Variadic list commands (RPUSHX, LPUSHX, LINSERT)

Following [this thread](https://groups.google.com/forum/#!topic/redis-db/vhxibwvWHaQ) I set out to implement variadic LINSERT.

I have started by separating the implementation of LINSERT from that of RPUSHX and LPUSHX since they were not so similar in the first place and would need to become even more different. Then I noticed making RPUSHX and LPUSHX variadic (like RPUSH / LPUSH) as well would be easy so I did that.

I am rather confident in those first commits, the most challenging one is [the last one](https://github.com/catwell/redis/commit/65f2cc49e340bcc9c7a55f661ba9839e40475ea8): actually making LINSERT variadic.

I had not expected that list iterators would break when used with ziplists (it is impossible to re-use an iterator after insertion). That means (unless I have missed something) that sometimes I need to iterate a ziplist up to the pivot as many times as there are elements to be inserted. I decided to try as hard as possible to avoid this case by converting to a regular list early if I could. This is why that code can look a bit complex and should probably be reviewed with attention...