Feature Enrichment with Spring Data Redis and Lettuce

Lettuce by far is the best Redis client out there for Java. In the java world, Annotations and Mappings are pretty popular. I build services using these concepts before however they were always under the service boundaries, never as shared libraries in order to avoid coupling. So today I record a video showing how we can use this feature and also extend the functionality to add custom enriched behavior.  We will be using Spring Boot 2, Spring Data Redis, and Lettuce as redis Client. We also will need to have redis running either as standalone / cluster or running on docker. We will create custom annotations in order to describe the behavior we want. I need to say that some people love and other people hate annotations, I have mixed feelings. Often for those that don't like it - check this out. Besides that, let's take a look. So Let's get started.




Our model is pretty simple. Simple Person POJO with Getters/Setters, toString, equals/hashCode all generated by Idea. You can see there is a custom annotation called UpperCase. The idea is to add custom features enrichment and make sure some fields are stored in the Upper case.


Now let's look at the annotation.

Custom Repository

Here is where the magic happens. I wrapped all CurdRepository operations and I'm delegating to the proper CrudRepository implementation at the end of the day. However I', also I have a reflection code that adds the feature enrichment I want based on the existence of the UpperCase annotation at the Entity fields.

The complete code is here.

Diego Pacheco

Popular posts from this blog

Podman in Linux

Java Agents

HMAC in Java