Transfer Beaker Memcache into SqlAlchemy (MySQL)
-
03-06-2022 - |
Question
I work with Flask and want to create some user sessions working on database.
Thanks to some help I found this snippet http://flask.pocoo.org/snippets/61/
from flask import Flask, request
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'ext:memcached',
'session.url': '127.0.0.1:11211',
'session.data_dir': './cache',
}
app = Flask(__name__)
@app.route('/')
def index():
session = request.environ['beaker.session']
if not session.has_key('value'):
session['value'] = 'Save in session'
session.save()
return "Session value set."
else:
return session['value']
if __name__ == '__main__':
app.wsgi_app = SessionMiddleware(app.wsgi_app, session_opts)
app.run(debug=True)
I have problems converting the example above into working SQLAlchemy running code. Not easy to find a tutorial for that. All I've got is http://beaker.readthedocs.org/en/latest/modules/sqla.html#module-beaker.ext.sqla
I know that session.type and url should be changed for ext:sqla and valid sql string to the database. But what's next?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow