websauna.system.core.redis module

Redis connection manager.

websauna.system.core.redis.create_redis(registry, connection_url=None, redis_client=<class 'redis.client.Redis'>, max_connections=16, **redis_options)[source]

Sets up Redis connection pool once at the start of a process.

Connection pool life cycle is the same as Pyramid registry which is the life cycle of a process (all threads).


max_connections – Default per-process connection pool limit

Return type


websauna.system.core.redis.get_redis(request_or_registry, url=None, redis_client=<class 'redis.client.Redis'>, **redis_options)[source]

Get a connection to Redis.


from websauna.system.core.redis import get_redis

def my_view(request):
    redis = get_redis(request)
    redis.set("myval", "foobar")

See Transient data data documentation.

See Redis command documentation.

See Redis Python client.

Compatible with pyramid_redis_session, see https://github.com/ericrasmussen/pyramid_redis_sessions/blob/master/pyramid_redis_sessions/connection.py

  • request – HTTP request object. NOTE: By legacy this argument also supports Registry object. However this behaviro will be deprecated.

  • url (Optional[str]) – An optional connection string that will be passed straight to StrictRedis.from_url. The connection string should be in the form redis://username:password@localhost:6379/0. If not given use the default from settings.

  • redis_options – A dict of keyword args to be passed straight to StrictRedis

Return type



Redis client


Check that we have a working Redis connection for session.

Execute this on startup, so we bail out without starting up with a missing Redis.

Return type



True if Redis connection works


Log Redis connection pool statistics at the end of each request.

Help to diagnose connection problems and web process lifetime issues.

We do not need to do specific cleanup, as connnection pool should clean up the connections when they go out of scope. Each Redis client function calls connection.release() at the end of operation.”


On every request dump Redis diagnostics information.