Memorystore Redis

Memorystore Redis Instance

Enable API

gcloud services enable servicenetworking.googleapis.com
gcloud services enable redis.googleapis.com
circle-exclamation

Create an Instance

Create an instance and attach it to the default VPC.

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

Get Instance IP Address

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

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 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:

circle-info

See redis-cli documentationarrow-up-right for more information.

Spring Boot Cache

Spring Boot can use Redisarrow-up-right to cache with annotationsarrow-up-right.

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.

circle-info

Read Spring Boot documentation on Cacheablearrow-up-right and Redisarrow-up-right for more information.

Spring Boot Session

Spring Boot can use Redis for session dataarrow-up-right with Spring Session Data Redisarrow-up-right.

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?