Skip to content

Commit

Permalink
Fix add() in RedisCache without a timeout
Browse files Browse the repository at this point in the history
When there is no timeout, this resulted in the key expiring immediately
after setting it, instead of not having an expiry at all.
  • Loading branch information
ThiefMaster committed Feb 16, 2021
1 parent f1899bc commit 8560521
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions flask_caching/backends/rediscache.py
Expand Up @@ -135,11 +135,14 @@ def set(self, key, value, timeout=None):
def add(self, key, value, timeout=None):
timeout = self._normalize_timeout(timeout)
dump = self.dump_object(value)
return self._write_client.setnx(
created = self._write_client.setnx(
name=self._get_prefix() + key, value=dump
) and self._write_client.expire(
name=self._get_prefix() + key, time=timeout
)
if created and timeout != -1:
self._write_client.expire(
name=self._get_prefix() + key, time=timeout
)
return created

def set_many(self, mapping, timeout=None):
timeout = self._normalize_timeout(timeout)
Expand Down

0 comments on commit 8560521

Please sign in to comment.