SessionRedisStore

Session store using the Redis in-memory data store.

class SessionRedisStore.SessionRedisStore(app)

Bases: SessionStore

A session store using Redis.

Stores the sessions in a single Redis store using ‘last write wins’ semantics. This increases fault tolerance and allows server clustering. In clustering configurations with concurrent writes for the same session(s) the last writer will always overwrite the session.

The keys are prefixed with a configurable namespace, allowing you to store other data in the same Redis system.

Cleaning/timing out of sessions is performed by Redis itself since no single application can know about the existence of all sessions or the last access for a given session. Besides it is built in Redis functionality. Consequently, correct sizing of Redis is necessary to hold all user’s session data.

You need to install the redis client to be able to use this module: https://pypi.python.org/pypi/redis You also need a Redis server: https://redis.io/

Contributed by Christoph Zwerschke, August 2016.

__init__(app)

Initialize the session store.

Subclasses must invoke super.

application()

Return the application owning the session store.

cleanStaleSessions(_task=None)

Clean stale sessions.

Redis does this on its own, so we do nothing here.

clear()

Clear the session store, removing all of its items.

decoder()

Return the value deserializer for the store.

encoder()

Return the value serializer for the store.

get(key, default=None)

Return value if key available, else return the default.

has_key(key)

Check whether the session store has a given key.

items()

Return a list with the (key, value) pairs for all sessions.

iteritems()

Return an iterator over the (key, value) pairs for all sessions.

iterkeys()

Return an iterator over the stored session keys.

itervalues()

Return an iterator over the stored values of all sessions.

keys()

Return a list with the keys of all the stored sessions.

pop(key, default=<class 'MiscUtils.NoDefault'>)

Return value if key available, else default (also remove key).

redisKey(key)

Create the real key with namespace to be used with Redis.

setEncoderDecoder(encoder, decoder)

Set the serializer and deserializer for the store.

setdefault(key, default=None)

Return value if key available, else default (also setting it).

storeAllSessions()

Permanently save all sessions in the store.

Should be used (only) when the application server is shut down. This closes the connections to the Redis server.

storeSession(session)

Save potentially changed session in the store.

values()

Return a list with the values of all stored sessions.