Stay organized with collections Save and categorize content based on your preferences.
You can connect to a Redis instance from the App Engine standard environment by using Serverless VPC Access.
SetupIf you have already installed the Google Cloud CLI and have created a Redis instance, you can skip these steps.
Install the gcloud CLI and initialize:
gcloud init
Follow the Quickstart Guide to create a Redis instance. Take note of the zone, IP address, and port of the Redis instance.
To connect from your App Engine app to your Redis instance's authorized VPC network, you must set up Serverless VPC Access.
Find your Redis instance's authorized network by running the command:
gcloud redis instances describe [INSTANCE_ID] --region [REGION]
Follow the instructions at Creating a connector to create a Serverless VPC Access connector. Make sure you create the connector in the same region as your app, and make sure the connector is attached to the Redis instance's authorized VPC network. Remember the name of the connector.
This sample HTTP server application establishes a connection to a Redis instance from an App Engine standard environment app.
Clone the repository for your desired programming language and navigate to the folder that contains the sample code:
Gogit clone https://github.com/GoogleCloudPlatform/golang-samples
cd golang-samples/memorystore/redis
Java
git clone https://github.com/GoogleCloudPlatform/java-docs-samples
cd java-docs-samples/memorystore/redis
Node.js
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples
cd nodejs-docs-samples/memorystore/redis
Python
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
cd python-docs-samples/memorystore/redis
This sample application increments a Redis counter every time the /
endpoint is accessed.
This application uses the github.com/gomodule/redigo/redis
client. Install it by running the following command:
go get github.com/gomodule/redigo/redis
Java
This application is Jetty 3.1 servlet-based.
It uses the Jedis library:
The AppServletContextListener
class is used to create a long-lived Redis connection pool:
The VisitCounterServlet
class is a web servlet that increments a Redis counter:
This application uses the redis
module.
This application uses Flask for web serving and the redis-py
package to communicate with the Redis instance.
To access the Redis instance, the App Engine app must be configured to use your Serverless VPC Access connector, and you must provide your Redis instance's connection details.
If you don't already have one, create an App Engine application.
Update the app's configuration to specify your Serverless VPC Access connector and the IP address and port of your Redis instance:
To deploy the application:
Copy necessary configuration files into the source directory:
GoCopy the app.yaml
and go.mod
files into the source directory:
cp gae_standard_deployment/{app.yaml,go.mod} .
Java
Copy the appengine-web.xml
file into the source directory:
mkdir -p src/main/webapp/WEB-INF
cp gae_standard_deployment/appengine-web.xml src/main/webapp/WEB-INF/
Node.js
Copy the app.yaml
file into the source directory:
cp gae_standard_deployment/app.yaml .
Python
Copy the app.yaml
file into the source directory:
cp gae_standard_deployment/app.yaml .
Run the deploy command:
Gogcloud app deploy
Java
mvn package appengine:stage
gcloud app deploy target/appengine-staging/app.yaml
Node.js
gcloud app deploy
Python
gcloud app deploy
After the deployment is complete, the command will output the URL where you can visit your app. If you visit this URL, you will see the count on your Redis instance increase each time the page is loaded.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4