guilleiguaran/fakeredis — pull request #42 by caius (2012-09-25 21:48:51+00:00)
Title: Multiple dbs

Decided to implement multiple databases properly, rather than having it done on connection details as we were before. (Reason for this is I have an app that uses multiple databases and I was getting key conflicts in the specs as they were using the same Memory instance due to how support for dbs was hacked in.)

It changes a few things, but nothing fundamental really. (Apologies for the size of the diff, changed a few things along the way to make it easier to add support for what I wanted.)

* Split the nested classes out into their own files for cleanliness.
* Switched to using accessor methods from accessing instance variables directly (makes refactoring easier)
* Caches instances (in `Memory.connect`) by host & port, as connecting to live redis instances is kept unique by just those keys of the connection options - the timeout/db/etc doesn't change the instance you connect to. Brings our behaviour more inline with live redis.
* Flushes all the databases in the rspec helper now - as any db in the redis instance may have keys in
* Stops tracking whether the server is connected or not, the redis-rb `Client` instance keeps track of that for us, and as we're technically never disconnected from the "server" (as it's an in-memory hash), it was just extra code for no real reason. (Added spec to make sure it works as expected still - and checked the spec against live redis instance to make sure that behaves as specced.)

All the specs run for me on 1.9.3p125 against fakeredis & my local redis instance (v2.4.14).