From d80f9f8ba0977c85a63c9ae3ba98515627978401 Mon Sep 17 00:00:00 2001 From: Cal Leeming Date: Wed, 25 Nov 2015 12:18:33 +0000 Subject: [PATCH 1/2] Fixes #613 This has been discussed in #514, #282 and #88. Using an explicit type check via `isinstance`, rather than duck typing, is typically considered unpythonic and breaks compatibility with mock objects such as FakeRedis. This patches removes the type check, and instead looks for a common method that should be present on the object as a hint on whether it's compatible or not. --- rq/compat/connections.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rq/compat/connections.py b/rq/compat/connections.py index 221e653..70c0bc6 100644 --- a/rq/compat/connections.py +++ b/rq/compat/connections.py @@ -22,9 +22,6 @@ PATCHED_METHODS = ['_setex', '_lrem', '_zadd', '_pipeline', '_ttl'] def patch_connection(connection): - if not isinstance(connection, StrictRedis): - raise ValueError('A StrictRedis or Redis connection is required.') - # Don't patch already patches objects if all([hasattr(connection, attr) for attr in PATCHED_METHODS]): return connection @@ -38,7 +35,8 @@ def patch_connection(connection): if hasattr(connection, 'pttl'): connection._pttl = fix_return_type(partial(StrictRedis.pttl, connection)) - elif isinstance(connection, StrictRedis): + # add support for mock redis objects + elif hasattr(connection, 'setex'): connection._setex = connection.setex connection._lrem = connection.lrem connection._zadd = connection.zadd From e76bde9bc0c2fed38f16d35579bce8e8762c6b8d Mon Sep 17 00:00:00 2001 From: Cal Leeming Date: Wed, 25 Nov 2015 18:39:22 +0000 Subject: [PATCH 2/2] Fix broken tests --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 291ee5b..16d9189 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ redis>=2.7 -click>=3.0.0 +click<6.0