From dbb8a3bede5a8c92022e2b1e3919ffc3328c0e89 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 20 Oct 2016 15:36:49 -0700 Subject: [PATCH 1/3] Add support for third-party memcache Change-Id: I4d4e6e5271f5ec1897f6745d2679e1d9240a450b --- appengine/flexible/memcache/README.md | 2 +- appengine/flexible/memcache/app.yaml | 13 +++++++++++-- appengine/flexible/memcache/main.py | 20 +++++++++++++++----- appengine/flexible/memcache/requirements.txt | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/appengine/flexible/memcache/README.md b/appengine/flexible/memcache/README.md index 292f28299c2..17516d866bc 100644 --- a/appengine/flexible/memcache/README.md +++ b/appengine/flexible/memcache/README.md @@ -20,6 +20,6 @@ Start your application: Deploy using `gcloud`: - gcloud beta app deploy app.yaml + gcloud app deploy app.yaml You can now access the application at `https://your-app-id.appspot.com`. diff --git a/appengine/flexible/memcache/app.yaml b/appengine/flexible/memcache/app.yaml index c7471497b97..1a6ff5decad 100644 --- a/appengine/flexible/memcache/app.yaml +++ b/appengine/flexible/memcache/app.yaml @@ -5,5 +5,14 @@ entrypoint: gunicorn -b :$PORT main:app runtime_config: python_version: 3 -beta_settings: - enable_app_engine_apis: true +# [START env_variables] +env_variables: + # If you are using the App Engine Memcache service (currently in alpha), + # uncomment this section and comment out the other Memcache variables. + # USE_APPENGINE_MEMCACHE: 1 + MEMCACHE_SERVER: your-memcache-server + # If you are using a Memcached server with SASL authentiation enabled, + # fill in these values with your username and password. + MEMCACHE_USERNAME: your-memcache-username + MEMCACHE_PASSWORD: your-memcache-password +# [END env_variables] diff --git a/appengine/flexible/memcache/main.py b/appengine/flexible/memcache/main.py index 64cebb38d8f..3ac0be54bba 100644 --- a/appengine/flexible/memcache/main.py +++ b/appengine/flexible/memcache/main.py @@ -16,16 +16,26 @@ import os from flask import Flask -from pymemcache.client.base import Client as MemcacheClient - +import pylibmc app = Flask(__name__) # [START client] -memcache_addr = os.environ.get('GAE_MEMCACHE_HOST', 'localhost') -memcache_port = os.environ.get('GAE_MEMCACHE_PORT', 11211) -memcache_client = MemcacheClient((memcache_addr, int(memcache_port))) +# Environment variables are defined in app.yaml. +if os.environ.get('USE_GAE_MEMCACHE'): + MEMCACHE_SERVER = ':'.join( + os.environ.get('GAE_MEMCACHE_HOST', 'localhost'), + os.environ.get('GAE_MEMCACHE_PORT', 11211)) +else: + MEMCACHE_SERVER = os.environ.get('MEMCACHE_SERVER', 'localhost:11211') + +MEMCACHE_USERNAME = os.environ.get('MEMCACHE_USERNAME') +MEMCACHE_PASSWORD = os.environ.get('MEMCACHE_PASSWORD') + +memcache_client = pylibmc.Client( + [MEMCACHE_SERVER], binary=True, + username=MEMCACHE_USERNAME, password=MEMCACHE_PASSWORD) # [END client] diff --git a/appengine/flexible/memcache/requirements.txt b/appengine/flexible/memcache/requirements.txt index f94c10ae4d7..6bd011b8312 100644 --- a/appengine/flexible/memcache/requirements.txt +++ b/appengine/flexible/memcache/requirements.txt @@ -1,3 +1,3 @@ Flask==0.11.1 gunicorn==19.6.0 -pymemcache==1.3.8 +pylibmc==1.5.1 From 7253c03ecd97707cfb1bf503d61cb1efab53657c Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 20 Oct 2016 15:49:33 -0700 Subject: [PATCH 2/3] Fix deploy command Change-Id: I738e3fa89ccf3814199e3f90c47f463df8ea7f0f --- appengine/flexible/memcache/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/flexible/memcache/README.md b/appengine/flexible/memcache/README.md index 17516d866bc..2daeb48b0f9 100644 --- a/appengine/flexible/memcache/README.md +++ b/appengine/flexible/memcache/README.md @@ -20,6 +20,6 @@ Start your application: Deploy using `gcloud`: - gcloud app deploy app.yaml + gcloud app deploy You can now access the application at `https://your-app-id.appspot.com`. From 57c4db660f8159091fd380bc829f41d5f8553856 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Thu, 20 Oct 2016 15:50:10 -0700 Subject: [PATCH 3/3] Fix env var naming Change-Id: Ic6d7468bb6145c92fe95c8e28d29c0cf6259dbd3 --- appengine/flexible/memcache/app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/flexible/memcache/app.yaml b/appengine/flexible/memcache/app.yaml index 1a6ff5decad..7315ae24220 100644 --- a/appengine/flexible/memcache/app.yaml +++ b/appengine/flexible/memcache/app.yaml @@ -9,7 +9,7 @@ runtime_config: env_variables: # If you are using the App Engine Memcache service (currently in alpha), # uncomment this section and comment out the other Memcache variables. - # USE_APPENGINE_MEMCACHE: 1 + # USE_GAE_MEMCACHE: 1 MEMCACHE_SERVER: your-memcache-server # If you are using a Memcached server with SASL authentiation enabled, # fill in these values with your username and password.