-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] memcache for GAE migration #74
Changes from 4 commits
8d1c848
a6e6c5c
f4ddbb8
07a5cfb
c2310ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/config.json | ||
*.pyc | ||
.idea | ||
lib |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
application: confweb | ||
version: 1 | ||
runtime: python27 | ||
threadsafe: yes | ||
api_version: 1 | ||
|
||
handlers: | ||
- url: .* | ||
script: app.app | ||
|
||
libraries: | ||
- name: jinja2 | ||
version: latest | ||
|
||
env_variables: | ||
CACHE_BACKEND: 'Memcached' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
import vendor | ||
vendor.add('lib') | ||
import os | ||
import sys | ||
|
||
from google.appengine.ext import vendor | ||
|
||
vendor.add('lib') | ||
|
||
# Fix for msvcrt import error https://github.com/gae-init/gae-init/pull/527 | ||
# Otherwise, GAE local dev server fails at "import msvcrt" in "click" package | ||
if os.name == 'nt': | ||
os.name = None | ||
sys.platform = '' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
import pickle | ||
import redis | ||
import os | ||
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/') or os.getenv('SERVER_SOFTWARE', '').startswith('Development/'): | ||
from google.appengine.api import memcache | ||
else: | ||
import memcache | ||
|
||
class Redis(object): | ||
def __init__(self, host, port, db): | ||
|
@@ -16,3 +21,33 @@ def get(self, key): | |
return None | ||
|
||
return pickle.loads(thing) | ||
|
||
class Memcached: | ||
def __init__(self, servers=[], debug=0): | ||
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/') or os.getenv('SERVER_SOFTWARE', '').startswith('Development/'): | ||
print "GAE memcache used" | ||
self.client = memcache | ||
else: | ||
def server_str(server): | ||
host = server.get('host') | ||
port = server.get('port') | ||
if not host: | ||
raise Exception("host missing in memcache servers settings" ) | ||
elif not port: | ||
raise Exception("port missing in memcache servers settings" ) | ||
else: | ||
return str( host + ':' + port ) | ||
|
||
if not servers: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. python で
と
の両方とも
で捕まえられましたっけ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nilはNoneのことですかね?でしたらどちらでも捕まえられます。 実際に試したところ、全部
を吐きました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
raise Exception("servers missing in memcache settings") | ||
else: | ||
server_settings = map( server_str, servers ) | ||
print "Normal memcache used" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これも! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 消しました。すいません! |
||
self.client = memcache.Client(server_settings, debug) | ||
|
||
def set(self, key, val, expires=0): | ||
self.client .set(key, val, expires) | ||
|
||
def get(self, key): | ||
return self.client.get(key) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ flask_oauth | |
jinja2 | ||
py-gfm | ||
redis | ||
python-memcached | ||
urllib3 | ||
wsgi-request-logger | ||
werkzeug |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デバッグプリント削除お願いしますー
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
消しました。