Skip to content

Commit 9aa3055

Browse files
author
Bill Prin
committed
[DO NOT MERGE] Add memcache sessions
1 parent e58661a commit 9aa3055

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

4-auth/bookshelf/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
# limitations under the License.
1414

1515
import json
16+
import os
1617
import logging
1718

1819
from flask import current_app, Flask, redirect, request, session, url_for
1920
import httplib2
21+
from pymemcache.client.base import Client as MemcacheClient
22+
23+
from flask.ext.session import MemcachedSessionInterface
24+
2025

2126
# [START include]
2227
from oauth2client.contrib.flask_util import UserOAuth2
@@ -25,10 +30,22 @@
2530
# [END include]
2631

2732

33+
# [START client]
34+
memcache_addr = os.environ.get('MEMCACHE_PORT_11211_TCP_ADDR', 'localhost')
35+
memcache_port = os.environ.get('MEMCACHE_PORT_11211_TCP_PORT', 11211)
36+
memcache_client = MemcacheClient((memcache_addr, int(memcache_port)))
37+
# [END client]
38+
39+
40+
2841
def create_app(config, debug=False, testing=False, config_overrides=None):
2942
app = Flask(__name__)
3043
app.config.from_object(config)
3144

45+
app.session_interface = MemcachedSessionInterface(memcache_client, 'sess')
46+
47+
48+
3249
app.debug = debug
3350
app.testing = testing
3451

4-auth/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ PyMySQL==0.7.2
77
Flask-PyMongo==0.4.1
88
PyMongo==3.2.2
99
six==1.10.0
10+
Flask-Session
11+
pymemcache==1.3.5

0 commit comments

Comments
 (0)