Skip to content

Commit

Permalink
Support redis-py v2 and v3
Browse files Browse the repository at this point in the history
Further to #946 this fixes the underlying issue in a easy-to-upgrade way
for end users, many of whom will have Redis installed via other means.
By having this check here and supporting both versions concurrently it
makes it easier for end users, and to use celery/kombu in projects that
use Redis elsewhere.

With this change it is possibly worth reverting #946
  • Loading branch information
ashb committed Nov 18, 2018
1 parent d9de66b commit 719e3bb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ def __init__(self, *args, **kwargs):
def append(self, message, delivery_tag):
delivery = message.delivery_info
EX, RK = delivery['exchange'], delivery['routing_key']
# TODO: Remove this once we soley on Redis-py 3.0.0+
if redis.VERSION[0] >= 3:
# Redis-py changed the format of zadd args in v3.0.0
zadd_args = [{time(): delivery_tag}]
else:
zadd_args = [time(), delivery_tag]

with self.pipe_or_acquire() as pipe:
pipe.zadd(self.unacked_index_key, time(), delivery_tag) \
pipe.zadd(self.unacked_index_key, *zadd_args) \
.hset(self.unacked_key, delivery_tag,
dumps([message._raw, EX, RK])) \
.execute()
Expand Down

0 comments on commit 719e3bb

Please sign in to comment.