Skip to content

Commit e97f4b8

Browse files
author
Theo Massard
committed
Allow to use a datetime.timedelta parameter for Client.set
Closes #145
1 parent bad4122 commit e97f4b8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

memcache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from __future__ import print_function
4949

5050
import binascii
51+
from datetime import timedelta
5152
from io import BytesIO
5253
import re
5354
import socket
@@ -709,7 +710,7 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False):
709710
expire, either as a delta number of seconds, or an absolute
710711
unix time-since-the-epoch value. See the memcached protocol
711712
docs section "Storage Commands" for more info on <exptime>. We
712-
default to 0 == cache forever.
713+
default to 0 == cache forever. Optionnaly now accepts a timedelta.
713714
714715
@param min_compress_len: The threshold length to kick in
715716
auto-compression of the value using the compressor
@@ -724,6 +725,8 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False):
724725
@param noreply: optional parameter instructs the server to not
725726
send the reply.
726727
'''
728+
if isinstance(time, timedelta):
729+
time = int(time.total_seconds())
727730
return self._set("set", key, val, time, min_compress_len, noreply)
728731

729732
def cas(self, key, val, time=0, min_compress_len=0, noreply=False):

0 commit comments

Comments
 (0)