mmcgrana/clj-redis — pull request #11 by ptaoussanis (2011-12-30 11:50:18+00:00)
Title: Refactored to use thread-locally-bound connection. Added sorting, transactions, pipelines, connection-pool options.

Hi Mark,

Sorry for the monolithic diff! I tried to layer the changes so you can follow through what's changed in each commit and pick+choose what you want.

The biggest change is obviously the refactoring to use a connection binding. This is breaking: consumers need to wrap in a (with-redis) call. Unfortunately I think a [/some kind of] binding approach will be necessary to support more intricate stuff like transactions and pipelines. Having the connection auto-lease on commands seems restrictive in these contexts.

Having said that, I'm not particularly fond of the approach I've taken here. Specifically, the type-hinting contortions are ugly. For one, compilation will throw lots of reflection warnings (though these shouldn't affect runtime performance).

I don't have any better ideas at the moment given the way Jedis seems to be structured. The only alternative I can think of would be to try and set everything up with prototypes, but that'd just about quadruple the codebase and make tracking Jedis more cumbersome.

Anyway, the proposed solution seems fast (similar to natively type-hinted performance) if not aesthetically pleasing. It's also pretty simple.

Transactions/pipelining don't work as well as I'd like either. E.g. they don't seem to be nestable (I can't tell from the docs if that should be possible), and bulk replies don't get converted to a native Clojure format in all circumstances.

Anyway, maybe some step in the general direction is better than no step.

Final note: these changes sorely need some unit-tests - I can't vouch for their reliability as-is.

All the best for the new year,

--
Peter Taoussanis