All eyes on AI: 2026 predictions The shifts that will shape your stack.

Read now
For developersSpring and Redis: Up and Running
Brian Sam-Bodden
Brian Sam-Bodden

#Objectives

Create the skeleton for the course’s Spring Boot application, configuring all dependencies and launching a suitably configured Redis instance for the course.

#Agenda

In this lesson, you will learn:
  • How to create and configure your Spring Boot application to use Redis
  • How to add a docker-compose file as a Git submodule to your application to configure and run Redis
  • How to add a Git submodule with the application’s sample raw data
  • How to launch a Redis instance suitable for the course
If you get stuck:

#Creating a skeleton spring boot application from scratch!

If you want to start with a fully configured Spring Boot application and wish to skip the “from scratch” part, skip to the section “Quick Start For Those In a Hurry.”
  1. In your browser, launch the Spring Initilizr
  2. Fill out the form using the following settings:
  • Project: Maven Project
  • Language: Java
  • Spring Boot: 2.4.4
  • Project Metadata:
    • Group: com.redislabs.edu
    • Artifact: redi2read
    • Name: redi2read
    • Description: Bookstore Web Services Powered by Redis
    • Package Name: com.redislabs.edu.redi2read
    • Packaging: JAR
    • Java: 11
  • Dependencies:
    • Spring Web
    • String Data Redis (Access + Driver)
    • Spring Security
    • Lombok
    • Spring Boot DevTools
Alternatively, you can use the following URL: http://bit.ly/spring-initlz-redi2read to launch the Spring Initilizr fully configured for the project. Click on GENERATE and Initializr will generate the zip file for the project and prompt you to download it to your local machine. Unzip the downloaded file (named redi2read.zip) in a suitable directory. For example on a Mac:

#Adding redismod docker compose Git submodule

Now that you have downloaded and unzipped the generated Spring Initializr application, change directories to the app directory (./redi2read) and inspect the contents.
You should have a full Maven-based Spring Boot application. Since we are going to be adding submodules, let’s put the application in git:
In the previous code block we initialized a git repo in our redi2read application directory. Adding an empty git commit facilitates future Git rebase operations.
Now that we have a basic Spring application, we need to configure a Redis instance for our application. We've created a docker-compose file in a git repository that you can add as a submodule to your application.
Git submodules, if you haven't encountered them, are a way to nest a git repo within another git repo. Read the Git documentation on submodules to learn more.
You’ll find this file in the redismod-docker-compose repo, hosted under the redis-developer organization in Github. The Repo contains a Docker Compose file configured to use the Redis “redismod” image, which is a Docker image that includes Redis built with support for JSON, Search, Graph, Time Series, Triggers and Functions, and Probabilistic data structures.
Modules included in the container:
  • Search: a full-featured search engine
  • Graph: a graph database
  • Time Series: a time-series database
  • JSON: a native JSON data type
  • Probabilistic: native Bloom and Cuckoo Filter data types
  • Triggers and Functions: a dynamic execution framework
To add the submodule, we use the git submodule command at the root of the project:
The command adds the contents of the passed repository under the folder named “docker,” which the command will create. At this point you can commit the changes made to the repository.

#Adding redi2read-data git submodule

The sample data for the application is also provided as a separate Git repo that we will add to our main repository: redi2read-data. The raw data for our application consists of a collection of JSON documents, representing books and users.
Books
The collection of JSON documents for book data comes from https://developers.google.com/books. Each file is labelled with the keyword/category used to construct it and an incrementing integer (some categories have more books than others) resulting in JSON such as:
We have an ID (the book ISBN), title, subtitle, description, page count, price, currency, language, thumbnail URL, a link to more information (the “infoLink” field), and an array of authors.
Users
The user data was randomly created using https://randomuser.me, which generated JSON like:
To add the submodule use the following command:
This submodule will load under the folder src/main/resource/data within the application folder to facilitate the loading of the data from the classpath. At this point you can commit your work so far to the git repo.

#Quick start for those in a hurry

To skip past all the steps outlined above (e.g., initializing a Spring app, adding submodules for data, etc.), simply clone the application with the --recurse-submodules option, and check out the branch named course/milestone-1

#Starting and testing Redis

Let's open a terminal window and change directories to the /docker directory under our project’s repository. To start our Docker Redis image, we’ll use the docker-compose command as follows:
You should see output similar to this:

#Using the Redis CLI

The redis-cli is the Redis command line interface, a simple program that allows you to send commands to Redis, and read the replies sent by the server, directly from the terminal.
Launching Redis CLI in the container
Find the container name using docker container ls:
With the name docker_redis_1 we can run bash in the container and then start the redis-cli:
Launching Redis CLI Locally​
If you already have the Redis CLI installed locally, you can launch it by simply entering:

#Testing our Redis instance

The most basic of commands, PING is used to “ping” the server. If we get a response back, we know that the Redis server is alive and kicking:
Checking for the installed Redis modules​
Since we have a customized Redis instance which includes several Redis modules, we can check for which modules have been installed:

#Getting familiar with Redis Commands

Keys are unique identifiers, whose value can be any one of the data types that Redis supports. These data types range from simple Strings, to Lists, Sets, and even Streams. Each data type has its own set of behaviors and commands associated with it.
Keys in a Redis database are distributed in a flat keyspace. Redis does not enforce a schema or naming policy for keys. This provides great flexibility, with the organization of the keyspace being the responsibility of the developer. We'll look at ways of managing this later in the course. Redis is famous for being an extremely fast database. This speed comes from the fact that it stores and serves all data from RAM rather than disk. Redis is durable, so your data will be persisted but all reads will be from a copy of the data held in RAM. This makes Redis an excellent choice for applications that require real time data access.

#External Resources

Here's some resources that we think will be useful to you as you discover Redis:
  • redis.io - the official website of open source Redis.
  • Redis Cloud - a fully managed cloud service from Redis with a free plan for getting started.
  • The official Redis Docker image.
  • For a comprehensive introduction to Redis, we recommend taking a look at the RU101: Introduction to Redis Data Structures course at Redis University. In this free online course, you’ll learn about the data structures in Redis, and you’ll see how to practically apply them in the real world.