summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Reifschneider <jafo00@gmail.com>2023-04-17 19:00:17 -0600
committerGitHub <noreply@github.com>2023-04-17 19:00:17 -0600
commit88b83c6f8bfe056735cf026ad869b933ff8fb892 (patch)
tree06bf25c40adeb25b46e5dc3dd372254c80ca41fb
parent12f9bf1fb70082e4dc704cfb037e96335bddaa5f (diff)
parentcf51ba46eb84f7b96ffdf74a5472cab380070325 (diff)
downloadpython-memcached-88b83c6f8bfe056735cf026ad869b933ff8fb892.tar.gz
Merge pull request #146 from tbobm/master
Allow to use a datetime.timedelta parameter for Client.set
-rw-r--r--memcache.py12
-rw-r--r--setup.py1
2 files changed, 7 insertions, 6 deletions
diff --git a/memcache.py b/memcache.py
index bbc2149..11da6c1 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
@@ -725,7 +726,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
@@ -740,6 +741,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):
@@ -1432,15 +1435,12 @@ class _Host(object):
If "raise_exception" is set, raise _ConnectionDeadError if the
read fails, otherwise return an empty string.
"""
- def empty_bytes(_: int) -> bytes:
- "Fake receiver that returns empty bytes when the socket isn't connected"
- return b''
-
buf = self.buffer
if self.socket:
recv = self.socket.recv
else:
- recv = empty_bytes
+ def recv(bufsize):
+ return b''
while True:
index = buf.find(b'\r\n')
diff --git a/setup.py b/setup.py
index 633fafd..d1e777a 100644
--- a/setup.py
+++ b/setup.py
@@ -3,6 +3,7 @@
from setuptools.depends import get_module_constant
from setuptools import setup # noqa
+dl_url = "https://github.com/linsomniac/python-memcached/releases/download/{0}/python-memcached-{0}.tar.gz"
version = get_module_constant('memcache', '__version__')
setup(