Skip to content

Commit ee13b7d

Browse files
authored
Merge pull request #772 from mikeroll/non-callable-keys
rate_limits: Remove option for non-callable `keys` argument to `incr_and_sum`
2 parents 60f95a7 + 119d6a0 commit ee13b7d

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ of those changes to CLEARTYPE SRL.
7474
| [@karolinepauls](https://karolinepauls.com) | Karoline Pauls |
7575
| [@gurelkaynak](https://gurel.kaynak.link) | Gurel Kaynak |
7676
| [@ksoviero-zengrc](https://github.com/ksoviero-zengrc) | Kevin Soviero |
77+
| [@mikeroll](https://github.com/mikeroll) | Mikhail Bulash |

dramatiq/rate_limits/backends/memcached.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl):
7272
if value > maximum:
7373
return False
7474

75-
# TODO: Drop non-callable keys in Dramatiq v2.
76-
key_list = keys() if callable(keys) else keys
77-
mapping = client.get_multi(key_list)
75+
mapping = client.get_multi(keys())
7876
total = amount + sum(mapping.values())
7977
if total > maximum:
8078
return False

dramatiq/rate_limits/backends/redis.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl):
8383
with self.client.pipeline() as pipe:
8484
while True:
8585
try:
86-
# TODO: Drop non-callable keys in Dramatiq v2.
87-
key_list = keys() if callable(keys) else keys
88-
pipe.watch(key, *key_list)
86+
pipe.watch(key, *keys())
8987
value = int(pipe.get(key) or b"0")
9088
value += amount
9189
if value > maximum:
9290
return False
9391

9492
# Fetch keys again to account for net/server latency.
95-
values = pipe.mget(keys() if callable(keys) else keys)
93+
values = pipe.mget(keys())
9694
total = amount + sum(int(n) for n in values if n)
9795
if total > maximum:
9896
return False

dramatiq/rate_limits/backends/stub.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def incr_and_sum(self, key, keys, amount, maximum, ttl):
6363
if value > maximum:
6464
return False
6565

66-
# TODO: Drop non-callable keys in Dramatiq v2.
67-
key_list = keys() if callable(keys) else keys
68-
values = sum(self._get(k, default=0) for k in key_list)
66+
values = sum(self._get(k, default=0) for k in keys())
6967
total = amount + values
7068
if total > maximum:
7169
return False

0 commit comments

Comments
 (0)