Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from __future__ import print_function

import binascii
from datetime import timedelta
from io import BytesIO
import re
import socket
Expand Down Expand Up @@ -725,7 +726,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 @@ -740,6 +741,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 Expand Up @@ -1432,15 +1435,12 @@ def readline(self, raise_exception=False):
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')
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down