diff --git a/swift/common/memcached.py b/swift/common/memcached.py index fdcbc745ae..35c37fca31 100644 --- a/swift/common/memcached.py +++ b/swift/common/memcached.py @@ -319,6 +319,7 @@ class MemcacheRing(object): interface consistent with set and set_multi methods :param timeout: ttl in memcache, deprecated, will be removed in future OpenStack releases + :returns: result of incrementing :raises MemcacheConnectionError: """ if timeout: @@ -370,12 +371,13 @@ class MemcacheRing(object): interface consistent with set and set_multi methods :param timeout: ttl in memcache, deprecated, will be removed in future OpenStack releases + :returns: result of decrementing :raises MemcacheConnectionError: """ if timeout: logging.warn("parameter timeout has been deprecated, use time") - self.incr(key, delta=-delta, time=(time or timeout)) + return self.incr(key, delta=-delta, time=(time or timeout)) def delete(self, key): """ diff --git a/test/unit/common/test_memcached.py b/test/unit/common/test_memcached.py index 5db798334d..f29c6db818 100644 --- a/test/unit/common/test_memcached.py +++ b/test/unit/common/test_memcached.py @@ -217,15 +217,15 @@ class TestMemcached(unittest.TestCase): mock = MockMemcached() memcache_client._client_cache['1.2.3.4:11211'] = MockedMemcachePool( [(mock, mock)] * 2) - memcache_client.incr('some_key', delta=5) + self.assertEquals(memcache_client.incr('some_key', delta=5), 5) self.assertEquals(memcache_client.get('some_key'), '5') - memcache_client.incr('some_key', delta=5) + self.assertEquals(memcache_client.incr('some_key', delta=5), 10) self.assertEquals(memcache_client.get('some_key'), '10') - memcache_client.incr('some_key', delta=1) + self.assertEquals(memcache_client.incr('some_key', delta=1), 11) self.assertEquals(memcache_client.get('some_key'), '11') - memcache_client.incr('some_key', delta=-5) + self.assertEquals(memcache_client.incr('some_key', delta=-5), 6) self.assertEquals(memcache_client.get('some_key'), '6') - memcache_client.incr('some_key', delta=-15) + self.assertEquals(memcache_client.incr('some_key', delta=-15), 0) self.assertEquals(memcache_client.get('some_key'), '0') mock.read_return_none = True self.assertRaises(memcached.MemcacheConnectionError, @@ -261,13 +261,13 @@ class TestMemcached(unittest.TestCase): mock = MockMemcached() memcache_client._client_cache['1.2.3.4:11211'] = MockedMemcachePool( [(mock, mock)] * 2) - memcache_client.decr('some_key', delta=5) + self.assertEquals(memcache_client.decr('some_key', delta=5), 0) self.assertEquals(memcache_client.get('some_key'), '0') - memcache_client.incr('some_key', delta=15) + self.assertEquals(memcache_client.incr('some_key', delta=15), 15) self.assertEquals(memcache_client.get('some_key'), '15') - memcache_client.decr('some_key', delta=4) + self.assertEquals(memcache_client.decr('some_key', delta=4), 11) self.assertEquals(memcache_client.get('some_key'), '11') - memcache_client.decr('some_key', delta=15) + self.assertEquals(memcache_client.decr('some_key', delta=15), 0) self.assertEquals(memcache_client.get('some_key'), '0') mock.read_return_none = True self.assertRaises(memcached.MemcacheConnectionError,