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.
Create the Redis service
- Log in to IBM Cloud, and go to the Catalog.
- Under Database, select Compose for Redis.
- 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:
Build and run the application
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:
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:
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.