Skip to content

Commit

Permalink
Fix redis setex usage (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Aug 30, 2020
1 parent 1eeec33 commit 8dc8ee1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion emmett/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.1"
__version__ = "2.0.2"
8 changes: 6 additions & 2 deletions emmett/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ def __init__(
except ImportError:
raise RuntimeError('no redis module found')
self._cache = redis.Redis(
host=host, port=port, password=password, db=db, **kwargs)
host=host, port=port, password=password, db=db, **kwargs
)

def _dump_obj(self, value: Any) -> bytes:
if isinstance(value, int):
Expand Down Expand Up @@ -428,7 +429,10 @@ def get(self, key: str) -> Any:
def set(self, key: str, value: Any, **kwargs):
dumped = self._dump_obj(value)
return self._cache.setex(
name=key, value=dumped, time=kwargs['duration'])
name=key,
time=kwargs['duration'],
value=dumped
)

@CacheHandler._key_prefix_
def clear(self, key: Optional[str] = None):
Expand Down
6 changes: 4 additions & 2 deletions emmett/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ def _delete_session(self):
def _save_session(self, expiration):
if current.session._modified:
self.redis.setex(
self.prefix + current.session._sid, current.session._dump,
expiration)
self.prefix + current.session._sid,
expiration,
current.session._dump
)
else:
self.redis.expire(self.prefix + current.session._sid, expiration)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Emmett"
version = "2.0.1"
version = "2.0.2"
description = "The web framework for inventors"
authors = ["Giovanni Barillari <gi0baro@d4net.org>"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit 8dc8ee1

Please sign in to comment.