Deprecated param timeout removed from memcached

Change-Id: Idf042a79f0db148bf9f28a9e360cb2a3c18d385a
This commit is contained in:
Ondřej Nový 2015-12-13 21:13:42 +01:00
parent 6830f6f33e
commit 6ade2908cc
2 changed files with 14 additions and 53 deletions

View File

@ -223,7 +223,7 @@ class MemcacheRing(object):
"""Returns a server connection to the pool."""
self._client_cache[server].put((fp, sock))
def set(self, key, value, serialize=True, timeout=0, time=0,
def set(self, key, value, serialize=True, time=0,
min_compress_len=0):
"""
Set a key/value pair in memcache
@ -233,22 +233,14 @@ class MemcacheRing(object):
:param serialize: if True, value is serialized with JSON before sending
to memcache, or with pickle if configured to use
pickle instead of JSON (to avoid cache poisoning)
:param timeout: ttl in memcache, this parameter is now deprecated. It
will be removed in next release of OpenStack,
use time parameter instead in the future
:time: equivalent to timeout, this parameter is added to keep the
signature compatible with python-memcached interface. This
implementation will take this value and sign it to the
parameter timeout
:param time: the time to live
:min_compress_len: minimum compress length, this parameter was added
to keep the signature compatible with
python-memcached interface. This implementation
ignores it.
"""
key = md5hash(key)
if timeout:
logging.warn("parameter timeout has been deprecated, use time")
timeout = sanitize_timeout(time or timeout)
timeout = sanitize_timeout(time)
flags = 0
if serialize and self._allow_pickle:
value = pickle.dumps(value, PICKLE_PROTOCOL)
@ -302,7 +294,7 @@ class MemcacheRing(object):
except (Exception, Timeout) as e:
self._exception_occurred(server, e, sock=sock, fp=fp)
def incr(self, key, delta=1, time=0, timeout=0):
def incr(self, key, delta=1, time=0):
"""
Increments a key which has a numeric value by delta.
If the key can't be found, it's added as delta or 0 if delta < 0.
@ -315,22 +307,16 @@ class MemcacheRing(object):
:param key: key
:param delta: amount to add to the value of key (or set as the value
if the key is not found) will be cast to an int
:param time: the time to live. This parameter deprecates parameter
timeout. The addition of this parameter is to make the
interface consistent with set and set_multi methods
:param timeout: ttl in memcache, deprecated, will be removed in future
OpenStack releases
:param time: the time to live
:returns: result of incrementing
:raises MemcacheConnectionError:
"""
if timeout:
logging.warn("parameter timeout has been deprecated, use time")
key = md5hash(key)
command = 'incr'
if delta < 0:
command = 'decr'
delta = str(abs(int(delta)))
timeout = sanitize_timeout(time or timeout)
timeout = sanitize_timeout(time)
for (server, fp, sock) in self._get_conns(key):
try:
with Timeout(self._io_timeout):
@ -358,7 +344,7 @@ class MemcacheRing(object):
self._exception_occurred(server, e, sock=sock, fp=fp)
raise MemcacheConnectionError("No Memcached connections succeeded.")
def decr(self, key, delta=1, time=0, timeout=0):
def decr(self, key, delta=1, time=0):
"""
Decrements a key which has a numeric value by delta. Calls incr with
-delta.
@ -367,18 +353,12 @@ class MemcacheRing(object):
:param delta: amount to subtract to the value of key (or set the
value to 0 if the key is not found) will be cast to
an int
:param time: the time to live. This parameter depcates parameter
timeout. The addition of this parameter is to make the
interface consistent with set and set_multi methods
:param timeout: ttl in memcache, deprecated, will be removed in future
OpenStack releases
:param time: the time to live
:returns: result of decrementing
:raises MemcacheConnectionError:
"""
if timeout:
logging.warn("parameter timeout has been deprecated, use time")
return self.incr(key, delta=-delta, time=(time or timeout))
return self.incr(key, delta=-delta, time=time)
def delete(self, key):
"""
@ -398,8 +378,8 @@ class MemcacheRing(object):
except (Exception, Timeout) as e:
self._exception_occurred(server, e, sock=sock, fp=fp)
def set_multi(self, mapping, server_key, serialize=True, timeout=0,
time=0, min_compress_len=0):
def set_multi(self, mapping, server_key, serialize=True, time=0,
min_compress_len=0):
"""
Sets multiple key/value pairs in memcache.
@ -409,23 +389,14 @@ class MemcacheRing(object):
:param serialize: if True, value is serialized with JSON before sending
to memcache, or with pickle if configured to use
pickle instead of JSON (to avoid cache poisoning)
:param timeout: ttl for memcache. This parameter is now deprecated, it
will be removed in next release of OpenStack, use time
parameter instead in the future
:time: equalvent to timeout, this parameter is added to keep the
signature compatible with python-memcached interface. This
implementation will take this value and sign it to parameter
timeout
:param time: the time to live
:min_compress_len: minimum compress length, this parameter was added
to keep the signature compatible with
python-memcached interface. This implementation
ignores it
"""
if timeout:
logging.warn("parameter timeout has been deprecated, use time")
server_key = md5hash(server_key)
timeout = sanitize_timeout(time or timeout)
timeout = sanitize_timeout(time)
msg = ''
for key, value in mapping.items():
key = md5hash(key)

View File

@ -201,16 +201,11 @@ class TestMemcached(unittest.TestCase):
self.assertEqual(
memcache_client.get('some_key'), ['simple str', u'utf8 str éà'])
self.assertTrue(float(mock.cache.values()[0][1]) == 0)
memcache_client.set('some_key', [1, 2, 3], timeout=10)
self.assertEqual(mock.cache.values()[0][1], '10')
memcache_client.set('some_key', [1, 2, 3], time=20)
self.assertEqual(mock.cache.values()[0][1], '20')
sixtydays = 60 * 24 * 60 * 60
esttimeout = time.time() + sixtydays
memcache_client.set('some_key', [1, 2, 3], timeout=sixtydays)
self.assertTrue(
-1 <= float(mock.cache.values()[0][1]) - esttimeout <= 1)
memcache_client.set('some_key', [1, 2, 3], time=sixtydays)
self.assertTrue(
-1 <= float(mock.cache.values()[0][1]) - esttimeout <= 1)
@ -313,11 +308,6 @@ class TestMemcached(unittest.TestCase):
[[4, 5, 6], [1, 2, 3]])
self.assertEqual(mock.cache.values()[0][1], '0')
self.assertEqual(mock.cache.values()[1][1], '0')
memcache_client.set_multi(
{'some_key1': [1, 2, 3], 'some_key2': [4, 5, 6]}, 'multi_key',
timeout=10)
self.assertEqual(mock.cache.values()[0][1], '10')
self.assertEqual(mock.cache.values()[1][1], '10')
memcache_client.set_multi(
{'some_key1': [1, 2, 3], 'some_key2': [4, 5, 6]}, 'multi_key',
time=20)
@ -328,7 +318,7 @@ class TestMemcached(unittest.TestCase):
esttimeout = time.time() + fortydays
memcache_client.set_multi(
{'some_key1': [1, 2, 3], 'some_key2': [4, 5, 6]}, 'multi_key',
timeout=fortydays)
time=fortydays)
self.assertTrue(
-1 <= float(mock.cache.values()[0][1]) - esttimeout <= 1)
self.assertTrue(