Skip to content

Commit

Permalink
Allow to use a datetime.timedelta parameter for Client.set
Browse files Browse the repository at this point in the history
Closes #145
  • Loading branch information
Theo Massard committed Jun 26, 2018
1 parent bad4122 commit 9cbc8c4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import binascii
from io import BytesIO
from datetime import timedelta
import re
import socket
import sys
Expand Down Expand Up @@ -709,7 +710,7 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False):
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
Expand All @@ -724,6 +725,8 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False):
@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):
Expand Down

0 comments on commit 9cbc8c4

Please sign in to comment.