Memorystore Redis

Memorystore Redis Instance

Enable API

gcloud services enable servicenetworking.googleapis.com
gcloud services enable redis.googleapis.com

Create an Instance

Create an instance and attach it to the default VPC.

gcloud redis instances create orders-cache \
  --size=1 --region=us-central1

Get Instance IP Address

gcloud redis instances describe orders-cache \
  --region=us-central1 --format="value(host)"

Connect to Instance

See Memorystore connectivity options to see how to connect to a Memorystore instance from different computing environments.

Computing Environment

Compute Engine

Kubernetes Engine

App Engine Flexible

App Engine Standard

Cloud Run

Cloud Function

You can test quickly by creating a Compute Engine instance in a zone within the same region:

SSH into the machine:

Install redis-cli:

Connect to the instance:

You can try different Redis commands, for example:

See redis-cli documentation for more information.

Spring Boot Cache

Spring Boot can use Redis to cache with annotations.

Dependency

Add the Spring Data Redis starter:

Configuration

Configure the Redis instance to connect to:

Enable Caching

Turn on caching capability explicitly with the @EnableCaching annotation:

Cacheable

Once you configured the Spring Boot with Redis and enabled caching, you can use the @Cacheable annotation to cache return values.

Read Spring Boot documentation on Cacheable and Redis for more information.

Spring Boot Session

Spring Boot can use Redis for session data with Spring Session Data Redis.

Dependency

Add the Spring Data Spanner starter:

Configuration

Configure the Redis instance to connect to:

Enable HTTP Session

Turn on caching capability explicitly with the @EnableSpringHttpSession annotation:

Samples

Last updated

Was this helpful?