Memorystore Redis Instance
Copy gcloud services enable servicenetworking.googleapis.com
gcloud services enable redis.googleapis.com circle-exclamation
Enabling this API may take a few minutes.
Create an Instance
Create an instance and attach it to the default VPC.
Copy gcloud redis instances create orders-cache \
--size=1 --region=us-central1 circle-exclamation
Creating a Redis instance may take a few minutes.
Get Instance IP Address
Copy gcloud redis instances describe orders-cache \
--region=us-central1 --format= " value(host) " circle-exclamation
The IP address is not a static IP address. If you create the instance, the IP address may be different.
Connect to Instance
See Memorystore connectivity options to see how to connect to a Memorystore instance from different computing environments.
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:
Spring Boot Cache
Spring Boot can use Redisarrow-up-right to cache with annotationsarrow-up-right .
Add the Spring Data Redis starter:
Configure the Redis instance to connect to:
Turn on caching capability explicitly with the @EnableCaching annotation:
Once you configured the Spring Boot with Redis and enabled caching, you can use the @Cacheable annotation to cache return values.
Spring Boot Session
Spring Boot can use Redis for session dataarrow-up-right with Spring Session Data Redisarrow-up-right .
Add the Spring Data Spanner starter:
Configure the Redis instance to connect to:
Enable HTTP Session
Turn on caching capability explicitly with the @EnableSpringHttpSession annotation: