Skip to content

Commit 4af2bcd

Browse files
authored
Fix flex memcache sample (GoogleCloudPlatform#837)
1 parent f0e1fd4 commit 4af2bcd

File tree

6 files changed

+19
-32
lines changed

6 files changed

+19
-32
lines changed

.kokoro/secrets-example.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export CLOUD_TASKS_APPENGINE_QUEUE=
105105
export CLOUD_TASKS_LOCATION=
106106
export CLOUD_TASKS_PULL_QUEUE=
107107

108+
# Redislabs Memcache
109+
export MEMCACHE_USERNAME=
110+
export MEMCACHE_PASSWORD=
111+
export MEMCACHE_ENDPOINT=
112+
108113
# WordPress
109114
export WORDPRESS_DB_INSTANCE_NAME=
110115
export WORDPRESS_DB_USER=$CLOUDSQL_USER

.kokoro/secrets.sh.enc

201 Bytes
Binary file not shown.

appengine/flexible/memcache/app.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,16 @@
2525
$app->register(new TwigServiceProvider());
2626
$app['twig.path'] = [ __DIR__ ];
2727
$app['memcached'] = function () {
28-
if (getenv('USE_GAE_MEMCACHE')) {
29-
$host = getenv('GAE_MEMCACHE_HOST') ?: 'localhost';
30-
$port = getenv('GAE_MEMCACHE_PORT') ?: '11211';
31-
} else {
32-
$server = getenv('MEMCACHE_SERVER') ?: 'localhost:11211';
33-
list($host, $port) = explode(':', $server);
34-
}
28+
# [START gae_flex_redislabs_memcache]
29+
$endpoint = getenv('MEMCACHE_ENDPOINT');
3530
$username = getenv('MEMCACHE_USERNAME');
3631
$password = getenv('MEMCACHE_PASSWORD');
37-
# [START gae_flex_redislabs_memcache]
38-
// $host = 'YOUR_MEMCACHE_HOST';
39-
// $port = 'YOUR_MEMCACHE_PORT';
40-
// $username = 'OPTIONAL_MEMCACHE_USERNAME';
41-
// $password = 'OPTIONAL_MEMCACHE_PASSWORD';
4232
$memcached = new Memcached;
4333
if ($username && $password) {
4434
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
4535
$memcached->setSaslAuthData($username, $password);
4636
}
37+
list($host, $port) = explode(':', $endpoint);
4738
if (!$memcached->addServer($host, $port)) {
4839
throw new Exception("Failed to add server $host:$port");
4940
}

appengine/flexible/memcache/app.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
runtime: php
2-
vm: true
2+
env: flex
33

44
runtime_config:
55
document_root: web
66

77
# [START gae_flex_redislabs_memcache_yaml]
88
env_variables:
9-
# If you are using the App Engine Memcache service (currently in alpha),
10-
# uncomment this section and comment out the other Memcache variables.
11-
# USE_GAE_MEMCACHE: 1
12-
MEMCACHE_SERVER: your-memcache-server
9+
# Set your memcache endpoint here. This should be in the format "host:port"
10+
MEMCACHE_ENDPOINT: "YOUR_MEMCACHE_ENDPOINT"
1311
# If you are using a Memcached server with SASL authentiation enabled,
1412
# fill in these values with your username and password.
1513
MEMCACHE_USERNAME: ""

appengine/flexible/memcache/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"twig/twig": "^1.24"
55
},
66
"require-dev": {
7+
"google/cloud-tools": "^0.9.0",
78
"gecko-packages/gecko-memcache-mock": "^2.0",
8-
"google/cloud-tools": "^0.6",
99
"paragonie/random_compat": "^2.0",
10-
"guzzlehttp/guzzle": "^6.3",
11-
"monolog/monolog": "^1.19"
10+
"monolog/monolog": "^1.19",
11+
"symfony/yaml": "~3.0|~4.0"
1212
}
1313
}

appengine/flexible/memcache/test/DeployTest.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
namespace Google\Cloud\Test\Memcache;
1818

1919
use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
20+
use Google\Cloud\TestUtils\TestTrait;
2021
use Google\Cloud\TestUtils\FileUtil;
2122
use Symfony\Component\Yaml\Yaml;
2223
use PHPUnit\Framework\TestCase;
2324

2425
class DeployTest extends TestCase
2526
{
27+
use TestTrait;
2628
use AppEngineDeploymentTrait;
2729

2830
public static function beforeDeploy()
@@ -31,19 +33,10 @@ public static function beforeDeploy()
3133
self::$gcloudWrapper->setDir($tmpDir);
3234
chdir($tmpDir);
3335

34-
$user = getenv('MEMCACHE_USERNAME');
35-
$password = getenv('MEMCACHE_PASSWORD');
36-
$server = getenv('MEMCACHE_SERVER');
37-
38-
if (empty($user) || empty($password) || empty($server)) {
39-
self::markTestSkipped('Must set MEMCACHE_USERNAME, ' .
40-
'MEMCACHE_PASSWORD, and MEMCACHE_SERVER');
41-
}
42-
4336
$appYaml = Yaml::parse(file_get_contents('app.yaml'));
44-
$appYaml['env_variables']['MEMCACHE_USERNAME'] = $user;
45-
$appYaml['env_variables']['MEMCACHE_PASSWORD'] = $password;
46-
$appYaml['env_variables']['MEMCACHE_SERVER'] = $server;
37+
$appYaml['env_variables']['MEMCACHE_ENDPOINT'] = self::requireEnv('MEMCACHE_ENDPOINT');
38+
$appYaml['env_variables']['MEMCACHE_USERNAME'] = self::requireEnv('MEMCACHE_USERNAME');
39+
$appYaml['env_variables']['MEMCACHE_PASSWORD'] = self::requireEnv('MEMCACHE_PASSWORD');
4740

4841
file_put_contents('app.yaml', Yaml::dump($appYaml));
4942
}

0 commit comments

Comments
 (0)