jodosha/redis-store — pull request #151 by jeremyruppel (2012-10-10 20:13:43+00:00)
Title: Increment expire support

This branch makes `increment` and `decrement` accept an optional hash of options, conforming to the `ActiveSupport::Cache::Store` interface:

```sh
increment(name, amount = 1, options = nil)
```

Additionally, `increment` and `decrement` now support the `:expires_in` option to support the pattern of expiring counters [described in the redis commands docs for INCR](http://redis.io/commands/incr). This syntax is the same as [dalli uses](https://github.com/mperham/dalli/blob/master/lib/active_support/cache/dalli_store.rb#L141), and at least [one other third party gem](https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/cache.rb#L15) depends on it. I'd love to see this supported in this implementation as well to ease in the transition from memcached to redis.

There's one thing I'm stuck on before I think this would be good to merge. If you read the description of the expiring counter pattern in the redis docs, it calls out the fact that they wrap the two operations in `MULTI/EXEC`. Trying to follow that advice resulted in the following error during the tests:

```sh
Redis::Distributed::CannotDistribute: MULTI cannot be used in Redis::Distributed
because the keys involved need to be on the same server or because we cannot
guarantee that the operation will be atomic.
```

I'd like to follow the docs as it makes sense for this operation to be atomic, but I could really use some advice on how to go about doing that. Thanks!