diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 15b7dbe0..ecdaab09 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -74,3 +74,4 @@ of those changes to CLEARTYPE SRL. | [@karolinepauls](https://karolinepauls.com) | Karoline Pauls | | [@gurelkaynak](https://gurel.kaynak.link) | Gurel Kaynak | | [@ksoviero-zengrc](https://github.com/ksoviero-zengrc) | Kevin Soviero | +| [@mikeroll](https://github.com/mikeroll) | Mikhail Bulash | diff --git a/dramatiq/rate_limits/backends/memcached.py b/dramatiq/rate_limits/backends/memcached.py index 691f5b55..3655354d 100644 --- a/dramatiq/rate_limits/backends/memcached.py +++ b/dramatiq/rate_limits/backends/memcached.py @@ -72,9 +72,7 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl): if value > maximum: return False - # TODO: Drop non-callable keys in Dramatiq v2. - key_list = keys() if callable(keys) else keys - mapping = client.get_multi(key_list) + mapping = client.get_multi(keys()) total = amount + sum(mapping.values()) if total > maximum: return False diff --git a/dramatiq/rate_limits/backends/redis.py b/dramatiq/rate_limits/backends/redis.py index aa64a95b..bee914ea 100644 --- a/dramatiq/rate_limits/backends/redis.py +++ b/dramatiq/rate_limits/backends/redis.py @@ -83,16 +83,14 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl): with self.client.pipeline() as pipe: while True: try: - # TODO: Drop non-callable keys in Dramatiq v2. - key_list = keys() if callable(keys) else keys - pipe.watch(key, *key_list) + pipe.watch(key, *keys()) value = int(pipe.get(key) or b"0") value += amount if value > maximum: return False # Fetch keys again to account for net/server latency. - values = pipe.mget(keys() if callable(keys) else keys) + values = pipe.mget(keys()) total = amount + sum(int(n) for n in values if n) if total > maximum: return False diff --git a/dramatiq/rate_limits/backends/stub.py b/dramatiq/rate_limits/backends/stub.py index a5fb7002..d5b8d33d 100644 --- a/dramatiq/rate_limits/backends/stub.py +++ b/dramatiq/rate_limits/backends/stub.py @@ -63,9 +63,7 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl): if value > maximum: return False - # TODO: Drop non-callable keys in Dramatiq v2. - key_list = keys() if callable(keys) else keys - values = sum(self._get(k, default=0) for k in key_list) + values = sum(self._get(k, default=0) for k in keys()) total = amount + values if total > maximum: return False