This example shows how to access a Memorystore Redis instance, that has both AUTH and in-transit encryption enabled, from a .NET 5 app.
- Clone the repo.
- Build and publish the application:
dotnet publish -c Release Redistest/Redistest.csproj
- Build the container image and push it to Google Cloud:
Replace [PROJECT_ID] with your project ID.
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
- Create a Memorystore Redis instance with AUTH and in-transit encryption enabled. For instructions see:
- Get the instance's host and port information and write them down.
- Get the AUTH string and write it down.
- Download the CA certificate and store it in the same folder as the dockerfile file. Name the file server-ca.pem.
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