This repository has been archived on 2020-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
magic-app/magic_app/session.py

33 lines
812 B
Python
Raw Normal View History

2020-07-04 11:12:31 +00:00
"""Session management interface module."""
from json import dumps, loads
class RedisSessionDB(dict):
"""Dict interface for Redis session management."""
def __init__(self, connection):
self.connection = connection
def keys(self):
return self.connection.keys()
def flushall(self):
self.connection.flushall()
def __getitem__(self, key):
value = self.connection.get(key)
if value is None:
raise KeyError(key)
utf8ified = str(value, "utf-8")
return loads(utf8ified)
def __setitem__(self, key, value):
value = dumps(value)
self.connection.set(key, value)
def __contains__(self, item):
return self.connection.exists(item)
def __delitem__(self, key):
self.connection.delete(key)