redis/redis-rb — pull request #356 by walkeriniraq (2013-08-21 21:13:48+00:00)
Title: Pipelined optional block

This is only my second attempt at contributing, so please be gentle.

My original plan was a simple change: when calling pipelined the block has a parameter that is the context of the pipeline, thus leaving the original redis object free to continue to make calls, start other pipelines, etc.

The use case is for a webapp that has a cache for data stored in redis. The cache is integrated with data retrieval, so on cache miss it goes and retrieves the data. In order to increase performance, I'm also using pipelined blocks to write data into my store. One of the pipelined blocks needs to retrieve data from the cache. This process worked fine when I was just yielding up separate redis connections. Once I started using connection pooling though - each thread has its own redis connection, the pipelined block changes the responses from commands, and my cache was not happy.

Thus the block param. It's optional, so it should be backwards compatible with current code, except for cases where the block was receiving a param and ignoring it (at least two of the test cases did this, so it's not entirely unlikely)

It seemed like a simple change, until I had to build a new Redis object for the pipelined block. Rather than hacking into the Redis object, I decided to make a base class that Redis would derive from.

That's when I realized that the Redis class was being used as a namespace throughout the gem. Which made changing the base class annoying...

I ended up changing the Redis class namespace to a RubyRedis module. It seemed cleaner to me. I'm open to other suggestions.

The tests pass though, so I'm curious what thoughts are. You can now do cool things like this:
```ruby
r.set 'mary', 'was a bullfrog'
r.pipelined do |pipeline|
pipeline.set 'mary', 'had a little lamb'
r.pipelined do |p2|
@first = p2.get 'mary'
end
@second = pipeline.get 'mary'
end
# @first.value => 'was a bullfrog'
# @second.value => 'had a little lamb'
```