Session Management

We are using Flask-Session to store user sessions server-side.

We are using this with the RedisSessionInterface. Locally using Digital Marketplace Runner (‘dmrunner’) this uses a Redis Docker image and on PaaS we use the Redis backing service.

Accessing redis sessions

Warning

There should be no day-to-day need to edit the Redis store and you risk breaking users’ sessions by doing so. Speak with other members of the team before accessing it.

You can use redis-cli to inspect and edit the Redis store:

localhost/dmrunner

docker exec -it $(docker ps -aqf "name=redis") redis-cli

PaaS

brew install redis

cf conduit digitalmarketplace_redis -- redis-cli

Getting a session value

From the dm_session cookie copy the first part of the value prior to the period character which should be a UUID.

From redis-cli run:

GET session:UUID

To show all keys run:

KEYS *

Decoding sessions

If you have got a session value from Redis it can be decoded using the Pickle library:

import pickle
value = \b'VALUE'
pickle.loads(value)