diff --git a/appengine/flexible/memcache/README.md b/appengine/flexible/memcache/README.md index 292f28299c2..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 beta app deploy app.yaml + gcloud app deploy 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..7315ae24220 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_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. + 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