Skip to content

Conversation

@bajnokk
Copy link
Owner

@bajnokk bajnokk commented May 13, 2021

Support Redis backend and automatic session expiry


@ttl.setter
def ttl(self, ttl):
# Changing the expiry does not affect stored records.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is (will be) false for MongoDB

@bajnokk bajnokk force-pushed the bajnokk branch 2 times, most recently from 4fc78a9 to b7c32b8 Compare May 21, 2021 06:31
bajnokk added 3 commits May 21, 2021 15:11
This change adds Redis as an alternative storage backend.

Implementation notes:
- The database name (which is a number) should be provided in the
connection URI.
- The keys are prefixed with the 'collection' string, so that it is
possible to share the same database with other applications.
- All values are stored as JSON documents ({"value": value}) in order to
try to keep the original data type, since Redis stores all values as bytes.
Note however that it is still possible that the retrieved object differs
from the stored one. (Dictionaries with non-string keys are an example.)
- All values are stored together with a TTL. The TTL is None by default,
which means that the record never expires. The TTL value can be set
during initialisation.

This commit changes the storage tests to use 'fakeredis' and 'mongomock'
instead of trying to launch a real MongoDB server. Expiration tests
have been added, too.
This changes the record layout in MongoDB so that the modification time
is now stored as a datetime object instead of a timestamp. It enables us
to create an auto-expiry index on that field.

Note that expiring objects is an asynchronous task in MongoDB. Unlike
Redis, MongoDB uses collection-level expiry settings, therefore it is
not possible to create multiple wrapper objects that operate on the same
collection with different TTL values.

Additionally, there is a minor change that allows specifying the
database name in the URI instead of an argument. In case the name is
specified both in the URI and the argument, the one in the argument is
silently ignored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants