In this tutorial, learn how to access a Compose for Redis caching service on IBM Cloud from a Spring Boot application.

Redis is a popular open source in-memory database implementing a networked, in-memory key-value store.

Spring Boot is a popular library that offers an opinionated take of the Spring Framework that allows for the rapid development and deployment of production-ready Spring applications.

Prerequisites

Create the Redis service

  1. Log in to IBM Cloud, and go to the Catalog.
  2. Under Database, select Compose for Redis.
  3. Click Create to create the service (the defaults should be fine).

When the service is fully deployed, which can take several minutes, you should see an overview screen similar to the following:

Redis configuration dashboard

Build and run the application

Download or clone this git repo from the Messaging with Redis Spring guide project:

git clone https://github.com/spring-guides/gs-messaging-redis

Under the folder complete/src/main/resources/, create the file application.properties. By default, Spring Boot will configure a Redis connection pointing to localhost:6379. To connect to the IBM Cloud Redis service, in application.properties, add the property spring.redis.url with the connection string to your Redis service. Using the above example, the application.properties file will look like this:

spring.redis.url=rediss://admin:VVARNSCYAQKXMNDX@portal268-12.bmix-eude-yp-5d1f970f-0301-4ccf-afc1-149a35073205.2949957883.composedb.com:19361

Under the complete folder, issue the following commands to build and run the application:

mvn clean install
java -jar target/gs-messaging-redis-0.1.0.jar

You should see the following output:

Redis console output

Summary

It’s that simple to create a Spring Boot application to access a Redis service on IBM Cloud! In my next tutorial, I’ll show you how to run the app on an IBM Cloud Kubernetes cluster using Kubernetes secrets to configure the service credentials.