|
Troy Unrau
troy at tblog.ath.cx
Tue Mar 15 04:42:15 EST 2005
I'm using postgresql for all of my website data, so naturally I was looking to
use it for storing of session data. The code doesn't seem to be postgresql
specific as it uses the standard python db api, and the SQL is fairly
standard.
from my source:
class SQLSession(Session.BaseSession):
def __init__(self, req,
db, table, key_colname, val_colname,
sid=0, secret=None,
timeout=0, lock=1):
"""
SQLSession class arguments:
req: mod_python request object
db: python DB API 2 object, such as a postgresql connection returned
from the psycopg module
table: name of the SQL table to store objects in
key_colname: name of the column in above table corresponding to the
session id key.
val_colname: name of the column in above table corresponding to the
actual session data
All other arguments follow from BaseSession in mod_python. See docs
for mod_python 3.1.x, section 4.8.1
"""
I have attached the code I've concocted that does the job for me, if anyone is
interested. It does work for me using a psycopg returned DB object for
postgresql.
One comment. Using this method, the apache lock calls don't seem to be
required, however I have left them in there since they don't seem to be doing
any harm. What /should/ happen though is for locking to take into account
the fact that there could be multiple apache servers in a cluster all using
the same session data from one database. In this case, a database oriented
locking scheme should be implemented instead.
Comments, suggestions and reuse are welcome. (the file is under a very
slightly modified BSD-style licence)
Cheers,
Troy Unrau
http://tblog.ath.cx/troy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SQLSession.py
Type: application/x-python
Size: 9431 bytes
Desc: not available
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050315/c9b4233e/SQLSession.bin
|