From e97f4b84b7b78a8931a40823823fad29c3db71d9 Mon Sep 17 00:00:00 2001 From: Theo Massard Date: Tue, 26 Jun 2018 12:17:39 +0200 Subject: Allow to use a datetime.timedelta parameter for Client.set Closes #145 --- memcache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'memcache.py') 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 . 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): -- cgit v1.2.1