Redis Integration With Helidon

Traditionally, software has been built using a "monolithic" architecture, i.e. a software design pattern in which the application is written using a single, large, highly complex codebase. However, this approach comes with a number of important disadvantages: inflexibility, poor scalability, and lower developer productivity due to the challenges of fully understanding and making changes to the software.

Instead, many organizations have been shifting to a "microservices"-based approach. In the microservices architecture, a software application is composed of many smaller, decoupled yet interconnected services, each with a dedicated goal or task. The advantages of the microservices paradigm include easier development, greater application scalability and resiliency, and less downtime.

Many frameworks and solutions have been released to facilitate microservices-based development. Java programmers, for example, enjoy access to frameworks for microservices such as Spring Boot, Micronaut, and Quarkus. Now there’s another option in the mix: Helidon.

Of course, large, robust software applications require an underlying database to store necessary information. These databases are implemented using solutions such as Redis, an open-source in-memory data structure store that has been named Stack Overflow’s "most loved" database technology for multiple years.

But is it possible to get these two parts of your tech stack to work together? What is Helidon, exactly, and how can you integrate Redis with Helidon?

What is Helidon?

First released by Oracle in 2018, Helidon is a Java framework for developing lightweight, speedy applications using a microservices architecture. Helidon originally began as the J4C (Java for Cloud) project and is built on top of Netty, a non-blocking I/O client-server framework for building network applications in Java.

Helidon comes in two different versions, depending on your development needs and preferences:

  • Helidon SE is designed for Java SE (Standard Edition) and lacks features such as dependency injection and functional programming. This version contains three APIs for building a microservice: the web server, the configuration, and the security.
  • Helidon MP is built on top of Helidon SE and implements the MicroProfile specification, which defines APIs in Java for building microservices.

According to Helidon project lead Dmitry Kornilov: "Helidon was designed for microservices only. It’s created from scratch and doesn’t have any legacy code. Helidon SE brings a more modern and reactive approach that developers like. We tried to make it very clear: no injection ‘magic’ is used, which makes a Helidon SE application easy to debug… For developers familiar with Java EE, we also have Helidon MP, our MicroProfile implementation."

How to Integrate Redis with Helidon

Redis is an open-source in-memory data structure store with a wide range of use cases and applications: NoSQL key-value databases, application caches, message brokers, and more. The advantages of using Redis as your enterprise database include:

  • Flexibility: From lists and strings to hashes, sets, and more, Redis already includes a rich array of pre-built data structures.
  • High availability: It’s easy to scale the sizes of Redis clusters up or down, depending on your usage needs.
  • In-memory: Unlike other database solutions, Redis data is stored in main memory, which permits extremely fast read and write operations.

Despite the many benefits of Redis, there are also a few drawbacks: for example, Redis isn’t automatically compatible with Java and other programming languages. For this reason, many Java developers have chosen to install third-party Redis Java clients such as Redisson.

Redisson is a third-party, open-source Redis Java client that simplifies the development process by offering many different implementations of Java distributed objects, collections, and constructs. What’s more, Redisson includes support for Helidon and other Java frameworks for building microservices-based applications.

Want to get started? Below is the simple three-step process for integrating Redis with Helidon in Redisson.

1. Add the redisson-helidon dependency to your project

If you’re using Maven for build automation, add the following text to your project file:

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-helidon</artifactId>
    <version>3.16.1</version>
</dependency>

If you’re using Gradle, add the following text:

compile 'org.redisson:redisson-helidon:3.16.1'

2. Add settings to the META-INF/microprofile-config.properties file

The microprofile-config.properties file is a configuration file that is structured in YAML format. Redisson offers multiple configuration possibilities depending on your needs, including single mode, replicated mode, cluster mode, sentinel mode, and proxy mode.

Below is an example of how to configure Redisson for working with Helidon, using a Redisson instance named "simple":

org.redisson.Redisson.simple.singleServerConfig.address=redis://127.0.0.1:6379
org.redisson.Redisson.simple.singleServerConfig.connectionPoolSize=64
org.redisson.Redisson.simple.threads=16
org.redisson.Redisson.simple.nettyThreads=32

3. Start using Redisson

Last but not least, to integrate Helidon with Redis, add an @Inject annotation (which denotes a dependency injection) to your Java code. For example:

@Inject
@Named("simple")
private RedissonClient redisson;

To perform an injection without using the @Named annotation, you can name your Redisson instance "default."

And that’s it! You’re now ready to use Redis with Helidon.

By installing Redisson, it’s much simpler to integrate Redis with Helidon and other valuable Java frameworks. For faster speeds and guaranteed 24/7 technical support with a service-level agreement, consider upgrading to Redisson PRO, which also offers additional features and functionality for Java developers in Redis.

Similar articles