Skip to main content

A tornado session implementation

Project description

https://img.shields.io/dub/l/vibe-d.svg

Environment

python version: >= 3.4

backend: redis,memcache,disk

required: tornadis, tornado, asyncmc

Installation

$ python3.x setup.py install

or

$ pip3.x install tornasess

Quickstarted

create session instance

from tornado import ioloop,gen
from tornasess  import SessionCacheFactory

config = {
   "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()

set session data

yield session.start()
session['name'] = 'xxxxx'
session.set("age",100)
session.multi_set({"address":"xxxx","sex":"xxx"})
yield session.end(expires=3600)

get session data

session_id = "GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="
yield session.start(session_id)
session['name']
session.get('name')
session.multi_get(['address','age','name'])
session.all()
#check session field existence
print('name' in session)
#get session id
session.session_id

#Note here!!
#   if you don't make change to session data,
#   it's not necessary to call 'session.end()'

delete session data

session_id = "GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="
yield session.start(session_id)
session.delete("name")
del session['age']
yield session.end()

destroy session

session_id = "GU3ZTM2YTA5ZWViNDE4MTgzM2Q3MzhhMjdjY2IyOWU="
yield session.start(session_id)
session.destroy()
yield session.end()

cache session instance

# after you used session ,you can cache it to cache factory
sess_fac.cache(session)

Version

0.1

LICENSE

MIT LICENSE

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

tornasess-0.6.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file tornasess-0.6.tar.gz.

File metadata

  • Download URL: tornasess-0.6.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tornasess-0.6.tar.gz
Algorithm Hash digest
SHA256 e7fab9b533a923342728056588393ca96e2d2571b6df7666958293af31a0bbc5
MD5 450e2bbb416d8e1ccbdd631c615283c3
BLAKE2b-256 531ab004a8af1123abb4f4d9e5d433ab40ae73236687f97f7ac77b3a7b45b6a0

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