Skip to content

Commit f7d0725

Browse files
committed
adds memorystore sample (WIP)
1 parent 0b98954 commit f7d0725

File tree

9 files changed

+2447
-0
lines changed

9 files changed

+2447
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
# If you would like to upload your .git directory, .gitignore file or files
11+
# from your .gitignore file, remove the corresponding line
12+
# below:
13+
.git
14+
.gitignore
15+
16+
# PHP Composer dependencies:
17+
vendor/

appengine/php72/memorystore/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Cloud SQL & Google App Engine
2+
3+
This sample application demonstrates how to use [Cloud SQL with Google App Engine](https://cloud.google.com/appengine/docs/php/cloud-sql/).
4+
5+
## Setup
6+
7+
Before you can run or deploy the sample, you will need to do the following:
8+
9+
1. Create a [Memorystore instance][memorystore_create]. You can do this from the
10+
[Cloud Console](https://console.developers.google.com) or via the
11+
[Cloud SDK](https://cloud.google.com/sdk). To create it via the SDK use the
12+
following command:
13+
14+
$ gcloud beta redis instances create YOUR_INSTANCE_NAME --region=REGION_ID
15+
16+
1. Update the environment variables `REDIS_HOST` and `REDIS_PORT` in `app.yaml`
17+
with your configuration values. These values are used when the application is
18+
deployed. Run the following command to get the values for your isntance:
19+
20+
$ gcloud beta redis instances describe YOUR_INSTANCE_NAME --region=REGION_ID
21+
22+
[memorystore_create]: https://cloud.google.com/memorystore/docs/redis/creating-managing-instances
23+
24+
## Run locally
25+
26+
You can connect to a local database instance by setting the `REDIS_` environment
27+
variables to your local instance. Alternatively, you can set them to your Cloud
28+
Memorystore instance, but you will need to create a firewall rule for this,
29+
which may be a safety concern.
30+
31+
```sh
32+
cd php-docs-samples/appengine/php72/memorystore
33+
34+
# set local connection parameters
35+
export REDIS_HOST=127.0.0.1
36+
export REDIS_PORT=6379
37+
38+
php -S localhost:8080
39+
```
40+
41+
> be sure the `REDIS_` environment variables are appropriate for your Redis
42+
instance.
43+
44+
Now you can view the app running at [http://localhost:8080](http://localhost:8080)
45+
in your browser.
46+
47+
## Deploy to App Engine
48+
49+
**Prerequisites**
50+
51+
- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/).
52+
53+
**Deploy with gcloud**
54+
55+
```
56+
gcloud config set project YOUR_PROJECT_ID
57+
gcloud app deploy
58+
gcloud app browse
59+
```
60+
61+
The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/`
62+
in your browser.

appengine/php72/memorystore/app.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This app.yaml is for deploying to instances of Cloud SQL running MySQL.
2+
# See app-postgres.yaml for running Cloud SQL with PostgreSQL.
3+
4+
runtime: php72
5+
6+
handlers:
7+
- url: /
8+
script: index.php
9+
10+
# [START gae_memorystore_app_yaml]
11+
# update with Redis instance host IP, port
12+
env_variables:
13+
REDIS_HOST: YOUR_REDIS_HOST
14+
REDIS_PORT: 6379
15+
# [END gae_memorystore_app_yaml]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"require-dev": {
3+
"phpunit/phpunit": "~5",
4+
"google/cloud-tools": "^0.6",
5+
"paragonie/random_compat": "^2.0"
6+
}
7+
}

0 commit comments

Comments
 (0)