underyx / flask-redis

A Flask extension for using Redis
Other
436 stars 71 forks source link

Add alternative Redis client support with `provider` #16

Closed thekuffs closed 9 years ago

thekuffs commented 9 years ago

I wanted to use mockredis_ for unit tests in another project. But I found that flask_redis did not support the substitution of another Redis client. And because flask_redis.Redis copies bound public methods over from redis.Redis at runtime, I couldn't patch in a unittest.Mock autospec.

So, I've added a new argument for the constructor called provider. This argument allows one to use mockredis or even StrictRedis as desired.

I've renamed the flask_redis.Redis class to flask_redis.FlaskRedis for clarity in the call stack.

I've removed the bound attribute copying to make it easier to debug. I would have gone with a subclass of redis.Redis, but it would have made it impossible to swap in MockRedis at runtime without Very Bad Things, like modifying __bases__.

I've removed the db parameter from the constructor as it duplicates functionality provided in the url and makes the underlying api more difficult.

I've also ported the tests from unittest to py.test proper.

This is an API-breaking change.

thekuffs commented 9 years ago

I didn't look at the existing issues or PRs before setting out on this, but looks like this overlaps #11, #13, #14, and #15. Save for registering it as an extension.

underyx commented 9 years ago

Hey there!

Thank you for the pull request! I ended up amending so much while applying your pull request that I decided to just implement the entire thing from scratch, in 18892582802c020de05c1773ddd0df692cf90230. One of the main differences is that the new changeset is entirely backwards compatible.

Please let me know if there's anything you'd do differently. Thanks!