kenn/redis-mutex — pull request #7 by simao (2013-06-20 15:42:54+00:00)
Title: - Remove `redis-classy` dependency

Hello,

First of all, thank you for developing this gem, it's really useful
and seems to cover all the tricky cases. Test coverage is also very
good, which made this refactoring possible.

This pull request introduces the following changes:

- Remove `redis-classy` dependency

- Add the possibility to use a custom redis connection and not one
saved in a class variable. This makes the use of connection pools
in redis apps possible, for example.

- The old API remains unchanged, although the initialization needs to
be different since we can avoid saving a redis instance in a class
variable, which I strongly advice against.

The reasons for this pull request are as follows:

1. With the current version, a redis connection is saved to an
instance variable in Redis::Classy.

This makes the use of connection pools in redis applications
impossible because the connection used by Redis::Mutex is always the
one saved in a class variable.

This implementation is not thread safe and it's not possible to use
more than one redis connection with Redis::Mutex.

This is important because many times when you use a Mutex you have a
high number of concurrent operations and you probably need to use
multiple redis connections.

2. IMHO, `redis-classy` introduces too much meta programming and makes
the code hard to read, when there is no need for it.

`redis-classy` makes the `Redis::Mutex` class behave exactly like a
redis connection, which I think is not at all the intention of a
`Redis::Mutex` class. This class should provide an API to use mutexes,
not to use redis. You could actually call redis operations (get, set,
etc etc) on `Redis::Mutex`

3. The new implementation is still not thread safer, but since each
`Redis::Mutex` instance can receive it's own `Redis` instance, it's
possible to implement a thread safe distributed mutex.

I will update the README further if you think this pull request can be accepted.