Skip to main content

Redis backend for CherryPy sessions

Project description

CherryPy kicks some serious arse in the ‘I am just a HTTP framework’ category! As of version 3.2 it supports 4 types of storage for sessions by default:

Redis is growing in popularity as an alternative to Memcached (and is fully supported on dotCloud!)

Installation

If you are not using pip yet. Install it and while you are at it consider using virtualenv too.

$ pip install cherrys

redis-py and CherryPy are required dependencies hence will be installed if necessary.

We recommend installing hiredis-py (a faster parser) as well.

$ pip install hiredis

Usage (and abusage)

To tell CherryPy which backend to use, we need to specify the storage_type for the sessions tool. You may want to read more about CherryPy configuration.

tools.sessions.storage_type : 'redis'

But CherryPy doesn’t know Redis. Hence the first thing we need to do is add the cherrys RedisSession class to cherrypy.lib.sessions.

import cherrys
cherrypy.lib.sessions.RedisSession = cherrys.RedisSession

It is that simple!

Config dictionary

There are 4 optional parameters you can set:

  • host [127.0.0.1]

  • port [6379]

  • db [0]

  • password [None]

A full config dictionary to activate Redis backed sessions would look like this.

config = {
    'tools.sessions.on' : True,
    'tools.sessions.storage_type' : 'redis',
    'tools.sessions.host' : 'REDIS_HOST',
    'tools.sessions.port' : 'REDIS_PORT',
    'tools.sessions.db' : 'REDIS_DB',
    'tools.sessions.password' : 'REDIS_PASSWORD'
    }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cherrys-0.3.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file cherrys-0.3.tar.gz.

File metadata

  • Download URL: cherrys-0.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cherrys-0.3.tar.gz
Algorithm Hash digest
SHA256 35d969ca596117eb95102c5379bb969a2688258b8a4c15057f15c129f84f0b3e
MD5 a1c6f426a00b240279ff5d78c24afa2a
BLAKE2b-256 ec5ee16d79d31986bafc44d4e82c2e18dbdeb5241ca9a848561c90e162f9282e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page