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

View File

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