- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .gitignore | ||
| COPYING | ||
| COPYING.LESSER | ||
| MANIFEST.in | ||
| pyproject.toml | ||
| README.md | ||
splent_feature_session_redis
Server-side sessions in Redis for SPLENT products, through Flask-Session
(config archetype). It is one of the session backends a product picks from;
splent_feature_session_filesystem is the other. It requires
splent_feature_redis, which runs the Redis server and says how to reach it.
What it does
When the app starts it sets Flask-Session to keep sessions in Redis:
SESSION_TYPE = "redis"andSESSION_REDIS, a client forREDIS_SESSION_URL: the serversplent_feature_redisconfigures, with its password, on the database it keeps for sessions. Tasks and anything else stored in Redis live in other databases, so they never mix with sessions.SESSION_PERMANENT = False, so a session ends with the browser unless a feature asks for more.SESSION_KEY_PREFIX = "<product>:"andSESSION_COOKIE_NAME = "<product>_session", taken fromSPLENT_APP. Two products served from the same host share cookies and may share one Redis, and the prefix and the cookie name keep their sessions apart.
Configuration
Where the sessions live is splent_feature_redis's to decide, so it is
configured there: REDIS_URL, REDIS_PASSWORD and REDIS_SESSION_DB. This
feature reads the result from app.config, never from the environment.
| Setting | Source | Purpose |
|---|---|---|
REDIS_SESSION_URL |
app.config, from splent_feature_redis |
Where the sessions are stored, password and database included. |
REDIS_URL |
app.config, from splent_feature_redis |
Used when REDIS_SESSION_URL is missing, which is what splent_feature_redis 1.5 and earlier provide. |
SPLENT_APP |
environment, else the app's package name | Product name used in the key prefix and the cookie name. |
With neither URL in the configuration the app does not start, and the error names the missing feature. A guessed default would only move the failure to the first request.
Tests
splent feature:test splent_feature_session_redis
The unit tests run inject_config against a bare Flask app with a mocked
Redis client, so no server is needed. One runs splent_feature_redis's
inject_config first, with the sessions on a database other than 0, so the
two features cannot disagree on a key name without a test failing. Against a
splent_feature_redis without a database per use (1.5), it is skipped.