Skip to content

idofl/dotnet-memorystore-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Accessing a secured Google Cloud Memorystore Redis from a .NET app

This example shows how to access a Memorystore Redis instance, that has both AUTH and in-transit encryption enabled, from a .NET 5 app.

Create the container image

  1. Clone the repo.
  2. Build and publish the application:
    dotnet publish -c Release Redistest/Redistest.csproj
  3. Build the container image and push it to Google Cloud:
    export PROJECT_ID=[PROJECT_ID]
    gcloud auth configure-docker
    docker build -t gcr.io/$PROJECT_ID/redistest:latest .
    docker push gcr.io/$PROJECT_ID/redistest:latest
    Replace [PROJECT_ID] with your project ID.

Create a secured Memorystore Redis instance

  1. Create a Memorystore Redis instance with AUTH and in-transit encryption enabled. For instructions see:
  2. Get the instance's host and port information and write them down.
  3. Get the AUTH string and write it down.
  4. Download the CA certificate and store it in the same folder as the dockerfile file. Name the file server-ca.pem.

Test the application

SSH into a Linux VM in your VPC that has the docker CLI installed and run the following command:

sudo docker run \
-e REDIS_HOST='HOST:POST' \
-e REDIS_AUTH='AUTH' \
gcr.io/$PROJECT_ID/redistest:latest

Replace HOST:PORT and AUTH with the values you wrote down for the instance's host IP, port, and AUTH string.

You should see the following output:

Value stored in Redis: 12345678
Value fetched from Redis: 12345678

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages