diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
a
|
b
|
|
83 | 83 | |
84 | 84 | def incr(self, key, delta=1, version=None): |
85 | 85 | key = self.make_key(key, version=version) |
| 86 | # memcached doesn't support a negative delta |
| 87 | if delta < 0: |
| 88 | return self._cache.decr(key, -delta) |
86 | 89 | try: |
87 | 90 | val = self._cache.incr(key, delta) |
88 | 91 | |
… |
… |
|
98 | 101 | |
99 | 102 | def decr(self, key, delta=1, version=None): |
100 | 103 | key = self.make_key(key, version=version) |
| 104 | if delta < 0: |
| 105 | return self._cache.incr(key, -delta) |
101 | 106 | try: |
102 | 107 | val = self._cache.decr(key, delta) |
103 | 108 | |
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
a
|
b
|
|
243 | 243 | self.assertEqual(self.cache.incr('answer', 10), 52) |
244 | 244 | self.assertEqual(self.cache.get('answer'), 52) |
245 | 245 | self.assertRaises(ValueError, self.cache.incr, 'does_not_exist') |
| 246 | self.assertEqual(self.cache.incr('answer', -10), 42) |
246 | 247 | |
247 | 248 | def test_decr(self): |
248 | 249 | # Cache values can be decremented |
… |
… |
|
252 | 253 | self.assertEqual(self.cache.decr('answer', 10), 32) |
253 | 254 | self.assertEqual(self.cache.get('answer'), 32) |
254 | 255 | self.assertRaises(ValueError, self.cache.decr, 'does_not_exist') |
255 | | |
| 256 | self.assertEqual(self.cache.decr('answer', -10), 42) |
| 257 | |
256 | 258 | def test_data_types(self): |
257 | 259 | # Many different data types can be cached |
258 | 260 | stuff = { |