A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/memorystore/docs/redis/connect-redis-instance-standard below:

Connecting to a Redis instance from an App Engine standard environment application | Memorystore for Redis

Skip to main content Connecting to a Redis instance from an App Engine standard environment application

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.

Setup

If you have already installed the Google Cloud CLI and have created a Redis instance, you can skip these steps.

  1. Install the gcloud CLI and initialize:

    gcloud init
    
  2. Follow the Quickstart Guide to create a Redis instance. Take note of the zone, IP address, and port of the Redis instance.

Configuring Serverless VPC Access

To connect from your App Engine app to your Redis instance's authorized VPC network, you must set up Serverless VPC Access.

  1. Find your Redis instance's authorized network by running the command:

    gcloud redis instances describe [INSTANCE_ID] --region [REGION]
    
  2. 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.

Sample application

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:

Go
git 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.

Go

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:

Node.js

This application uses the redis module.

Python

This application uses Flask for web serving and the redis-py package to communicate with the Redis instance.

Preparing the application for deployment

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.

  1. If you don't already have one, create an App Engine application.

  2. Update the app's configuration to specify your Serverless VPC Access connector and the IP address and port of your Redis instance:

Deploying the application to the App Engine standard environment

To deploy the application:

  1. Copy necessary configuration files into the source directory:

    Go

    Copy 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 .
    
  2. Run the deploy command:

    Go
    gcloud 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