diff options
author | Theo Massard <theo.massard@1000mercis.com> | 2018-06-26 12:17:39 +0200 |
---|---|---|
committer | Theo Massard <theo.massard@1000mercis.com> | 2018-06-26 12:25:44 +0200 |
commit | e97f4b84b7b78a8931a40823823fad29c3db71d9 (patch) | |
tree | 75fcf088c1cea2a445ea7586f7c8a986bed6c4fa | |
parent | bad41222379102e3f18f6f2f7be3ee608de6fbff (diff) | |
download | python-memcached-e97f4b84b7b78a8931a40823823fad29c3db71d9.tar.gz |
Allow to use a datetime.timedelta parameter for Client.set
Closes #145
-rw-r--r-- | memcache.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/memcache.py b/memcache.py index 05b6657..c90af62 100644 --- a/memcache.py +++ b/memcache.py @@ -48,6 +48,7 @@ More detailed documentation is available in the L{Client} class. from __future__ import print_function import binascii +from datetime import timedelta from io import BytesIO import re import socket @@ -709,7 +710,7 @@ class Client(threading.local): expire, either as a delta number of seconds, or an absolute unix time-since-the-epoch value. See the memcached protocol docs section "Storage Commands" for more info on <exptime>. We - default to 0 == cache forever. + default to 0 == cache forever. Optionnaly now accepts a timedelta. @param min_compress_len: The threshold length to kick in auto-compression of the value using the compressor @@ -724,6 +725,8 @@ class Client(threading.local): @param noreply: optional parameter instructs the server to not send the reply. ''' + if isinstance(time, timedelta): + time = int(time.total_seconds()) return self._set("set", key, val, time, min_compress_len, noreply) def cas(self, key, val, time=0, min_compress_len=0, noreply=False): |