API¶
-
pyramid_redis_sessions.RedisSessionFactory(secret, timeout=1200, cookie_name='session', cookie_max_age=None, cookie_path='/', cookie_domain=None, cookie_secure=False, cookie_httponly=True, cookie_on_exception=True, url=None, host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None, client_callable=None, serialize=<built-in function dumps>, deserialize=<built-in function loads>, id_generator=<function _generate_session_id>)[source]¶ Constructs and returns a session factory that will provide session data from a Redis server. The returned factory can be supplied as the
session_factoryargument of apyramid.config.Configuratorconstructor, or used as thesession_factoryargument of thepyramid.config.Configurator.set_session_factory()method.Parameters:
secretA string which is used to sign the cookie.timeoutA number of seconds of inactivity before a session times out.cookie_nameThe name of the cookie used for sessioning. Default:session.cookie_max_ageThe maximum age of the cookie used for sessioning (in seconds). Default:None(browser scope).cookie_pathThe path used for the session cookie. Default:/.cookie_domainThe domain used for the session cookie. Default:None(no domain).cookie_secureThe ‘secure’ flag of the session cookie. Default:False.cookie_httponlyThe ‘httpOnly’ flag of the session cookie. Default:True.cookie_on_exceptionIfTrue, set a session cookie even if an exception occurs while rendering a view. Default:True.urlA connection string for a Redis server, in the format: redis://username:password@localhost:6379/0 Default:None.hostA string representing the IP of your Redis server. Default:localhost.portAn integer representing the port of your Redis server. Default:6379.dbAn integer to select a specific database on your Redis server. Default:0passwordA string password to connect to your Redis server/database if required. Default:None.client_callableA python callable that accepts a Pyramid request and Redis config options and returns a Redis client such as redis-py’s StrictRedis. Default:None.serializeA function to serialize the session dict for storage in Redis. Default:cPickle.dumps.deserializeA function to deserialize the stored session data in Redis. Default:cPickle.loads.id_generatorA function to create a unique ID to be used as the session key when a session is first created. Default: private function that uses sha1 with the time and random elements to create a 40 character unique ID.The following arguments are also passed straight to the
StrictRedisconstructor and allow you to further configure the Redis client:socket_timeout connection_pool charset errors unix_socket_path
-
pyramid_redis_sessions.includeme(config)[source]¶ This function is detected by Pyramid so that you can easily include pyramid_redis_sessions in your main method like so:
config.include('pyramid_redis_sessions')
Parameters:
configA Pyramidconfig.Configurator
-
pyramid_redis_sessions.session_factory_from_settings(settings)[source]¶ Convenience method to construct a
RedisSessionFactoryfrom Paste config settings. Only settings prefixed with “redis.sessions” will be inspected and, if needed, coerced to their appropriate types (for example, casting thetimeoutvalue as an int).Parameters:
settingsA dict of Pyramid application settings
-
RedisSession.adjust_timeout_for_session(session, *arg, **kw)¶