Skip to content

Commit 32a1a3f

Browse files
committed
saner handling of decr/incr vs decrby/incrby
1 parent 0bd66a9 commit 32a1a3f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

redis/client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,17 +1152,16 @@ def decr(self, name, amount=1):
11521152
Decrements the value of ``key`` by ``amount``. If no key exists,
11531153
the value will be initialized as 0 - ``amount``
11541154
"""
1155-
return self.execute_command('DECRBY', name, amount)
1155+
# An alias for ``decr()``, because it is already implemented
1156+
# as DECRBY redis command.
1157+
return self.decrby(name, amount)
11561158

11571159
def decrby(self, name, amount=1):
11581160
"""
11591161
Decrements the value of ``key`` by ``amount``. If no key exists,
11601162
the value will be initialized as 0 - ``amount``
11611163
"""
1162-
1163-
# An alias for ``decr()``, because it is already implemented
1164-
# as DECRBY redis command.
1165-
return self.decr(name, amount)
1164+
return self.execute_command('DECRBY', name, amount)
11661165

11671166
def delete(self, *names):
11681167
"Delete one or more keys specified by ``names``"
@@ -1240,17 +1239,16 @@ def incr(self, name, amount=1):
12401239
Increments the value of ``key`` by ``amount``. If no key exists,
12411240
the value will be initialized as ``amount``
12421241
"""
1243-
return self.execute_command('INCRBY', name, amount)
1242+
return self.incrby(name, amount)
12441243

12451244
def incrby(self, name, amount=1):
12461245
"""
12471246
Increments the value of ``key`` by ``amount``. If no key exists,
12481247
the value will be initialized as ``amount``
12491248
"""
1250-
12511249
# An alias for ``incr()``, because it is already implemented
12521250
# as INCRBY redis command.
1253-
return self.incr(name, amount)
1251+
return self.execute_command('INCRBY', name, amount)
12541252

12551253
def incrbyfloat(self, name, amount=1.0):
12561254
"""

tests/test_commands.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ def test_decr(self, r):
301301
assert r.decr('a', amount=5) == -7
302302
assert r['a'] == b'-7'
303303

304+
def test_decrby(self, r):
305+
assert r.decrby('a', amount=2) == -2
306+
assert r.decrby('a', amount=3) == -5
307+
assert r['a'] == b'-5'
308+
304309
def test_delete(self, r):
305310
assert r.delete('a') == 0
306311
r['a'] = 'foo'

0 commit comments

Comments
 (0)