Customizing session id strings?

90 views
Skip to first unread message

Roy Smith

unread,
Aug 16, 2012, 12:12:21 PM8/16/12
to django...@googlegroups.com
We're using django.contrib.sessions.backends.cache.  We use mongodb for our datastore, so we don't use the django model/database support at all.

The standard django session machinery generates 32-character hex strings (128 bits) for session ids.  We store the session_id in many places in our database (and index many collections on it), so shorter ids would be a big win.  Mongo uses 96-bits for its object ids.  I figure we don't need any more than that.  Base-64 encoding gives 16 characters.

So, the question is, is there any hook to allow us to generate our own session_ids for django.contrib.sessions.backends.cache to use?  I'm tempted to just subclass sessions.backends.cache and override _get_new_session_key(), but overriding underscore-prepended things sounds a little funky.

BTW, looking at base.py, why does it go to all the weird md5/pid/time stuff?  Why not just call uuid() and be done with it?

Pengfei Xue

unread,
Aug 16, 2012, 11:11:34 PM8/16/12
to django...@googlegroups.com
git://github.com/martinrusev/django-redis-sessions.git

take a look at this implementation for redis I think that's what you want

-- 
Sincerely,
Pengfei Xue





已使用 Sparrow

已使用 Sparrow
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/foQbHzVBpq8J.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages