Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appengine/flexible/memcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
13 changes: 11 additions & 2 deletions appengine/flexible/memcache/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
20 changes: 15 additions & 5 deletions appengine/flexible/memcache/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_APPENGINE_MEMCACHE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why prefer that when the GAE env vars all use the "GAE" initialism?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're inconsistent. change this one or the one in app.yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, gotcha. Sorry! Fixed.

MEMCACHE_SERVER = ':'.join(
os.environ.get('GAE_MEMCACHE_HOST', 'localhost'),
os.environ.get('GAE_MEMCACHE_PORT', 11211))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just check these env vars instead of having a separate env var as a flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because eventually these will always be set, and I don't want code that's using third-party memcache to suddenly start using GAE memcache.

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]


Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/memcache/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==0.11.1
gunicorn==19.6.0
pymemcache==1.3.8
pylibmc==1.5.1