Skip to content

Commit 899a9ba

Browse files
author
Jon Wayne Parrott
authored
Add support for third-party memcache (#600)
1 parent 1fb0e03 commit 899a9ba

4 files changed

Lines changed: 28 additions & 9 deletions

File tree

appengine/flexible/memcache/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Start your application:
2020

2121
Deploy using `gcloud`:
2222

23-
gcloud beta app deploy app.yaml
23+
gcloud app deploy
2424

2525
You can now access the application at `https://your-app-id.appspot.com`.

appengine/flexible/memcache/app.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@ entrypoint: gunicorn -b :$PORT main:app
55
runtime_config:
66
python_version: 3
77

8-
beta_settings:
9-
enable_app_engine_apis: true
8+
# [START env_variables]
9+
env_variables:
10+
# If you are using the App Engine Memcache service (currently in alpha),
11+
# uncomment this section and comment out the other Memcache variables.
12+
# USE_GAE_MEMCACHE: 1
13+
MEMCACHE_SERVER: your-memcache-server
14+
# If you are using a Memcached server with SASL authentiation enabled,
15+
# fill in these values with your username and password.
16+
MEMCACHE_USERNAME: your-memcache-username
17+
MEMCACHE_PASSWORD: your-memcache-password
18+
# [END env_variables]

appengine/flexible/memcache/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,26 @@
1616
import os
1717

1818
from flask import Flask
19-
from pymemcache.client.base import Client as MemcacheClient
20-
19+
import pylibmc
2120

2221
app = Flask(__name__)
2322

2423

2524
# [START client]
26-
memcache_addr = os.environ.get('GAE_MEMCACHE_HOST', 'localhost')
27-
memcache_port = os.environ.get('GAE_MEMCACHE_PORT', 11211)
28-
memcache_client = MemcacheClient((memcache_addr, int(memcache_port)))
25+
# Environment variables are defined in app.yaml.
26+
if os.environ.get('USE_GAE_MEMCACHE'):
27+
MEMCACHE_SERVER = ':'.join(
28+
os.environ.get('GAE_MEMCACHE_HOST', 'localhost'),
29+
os.environ.get('GAE_MEMCACHE_PORT', 11211))
30+
else:
31+
MEMCACHE_SERVER = os.environ.get('MEMCACHE_SERVER', 'localhost:11211')
32+
33+
MEMCACHE_USERNAME = os.environ.get('MEMCACHE_USERNAME')
34+
MEMCACHE_PASSWORD = os.environ.get('MEMCACHE_PASSWORD')
35+
36+
memcache_client = pylibmc.Client(
37+
[MEMCACHE_SERVER], binary=True,
38+
username=MEMCACHE_USERNAME, password=MEMCACHE_PASSWORD)
2939
# [END client]
3040

3141

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==0.11.1
22
gunicorn==19.6.0
3-
pymemcache==1.3.8
3+
pylibmc==1.5.1

0 commit comments

Comments
 (0)