I am writi开发者_StackOverflow中文版ng a lightweight Tornado based comet server. I would like to store the "self" object in redis to maintain the state.. Will this work?
For a start, i cant even serialize self to be stored in Redis..
This is the error
File "sessionsupport.py", line 27, in get
this = cPickle.dumps(self,1)
File "/home/test/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle instancemethod objects
any suggestions on how i would do this?
I'm unsure of if the self
object refers to an instance of RequestHandler
, or maybe some type of Session
instance you have. Whichever it is, you're probably going to want to convert your object to a dict before pickling and saving to redis. At least, that's what I do with MongoDB. My Tornado sessions:
- Are
dict
s that contain any data I want to persist throughout the users' sessions - Are assigned an ID which is:
- Saved along with the dict in my datastore (redis or MongoDB)
- Stored in a user's cookie
精彩评论