龙卷风会议执行
tornasess的Python项目详细描述
环境
python版本:>;=3.4
后端:redis、memcache、磁盘
必需:tornadis、tornado、asyncmc
安装
$ python3.x setup.py install
或
$ pip3.x install tornasess
快速启动
创建会话实例
fromtornadoimportioloop,genfromtornasessimportSessionCacheFactoryconfig={"host":"localhost","port":6379,}sess_fac=SessionCacheFactory("redis",config)# or# config = {# "host":["192.168.0.1","192.168.0.2"],# "port":[4000,5000]# }# sess_fac = SessionCacheFactory("memcache", config)### or# config = {"root":"/tmp"}# sess_fac = SessionCacheFactory("disk", config)#session=sess_fac.get_session()
设置会话数据
yieldsession.start()session['name']='xxxxx'session.set("age",100)session.multi_set({"address":"xxxx","sex":"xxx"})yieldsession.end(expires=3600)
获取会话数据
session_id="GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="yieldsession.start(session_id)session['name']session.get('name')session.multi_get(['address','age','name'])session.all()#check session field existenceprint('name'insession)#get session idsession.session_id#Note here!!# if you don't make change to session data,# it's not necessary to call 'session.end()'
删除会话数据
session_id="GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="yieldsession.start(session_id)session.delete("name")delsession['age']yieldsession.end()
销毁会话
session_id="GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="yieldsession.start(session_id)session.destroy()yieldsession.end()
缓存会话实例
# after you used session ,you can cache it to cache factorysess_fac.cache(session)
版本
0.1