Skip to content

Commit

Permalink
Allow timeout=None, fixes #62
Browse files Browse the repository at this point in the history
  • Loading branch information
mkai committed Mar 13, 2014
1 parent 4a0911a commit 7e1c308
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions redis_cache/cache.py
Expand Up @@ -208,7 +208,7 @@ def get(self, key, default=None, version=None):
return result

def _set(self, key, value, timeout, client, _add_only=False):
if timeout == 0:
if timeout is None or timeout == 0:
if _add_only:
return client.setnx(key, value)
return client.set(key, value)
Expand All @@ -231,12 +231,14 @@ def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None, client=None, _a
key = self.make_key(key, version=version)
if timeout is DEFAULT_TIMEOUT:
timeout = self.default_timeout
if timeout is not None:
timeout = int(timeout)

# If ``value`` is not an int, then pickle it
if not isinstance(value, int) or isinstance(value, bool):
result = self._set(key, pickle.dumps(value), int(timeout), client, _add_only)
result = self._set(key, pickle.dumps(value), timeout, client, _add_only)
else:
result = self._set(key, value, int(timeout), client, _add_only)
result = self._set(key, value, timeout, client, _add_only)
# result is a boolean
return result

Expand Down

0 comments on commit 7e1c308

Please sign in to comment.