Generator-jhipster: Add Redis support for Spring cache abstraction

Created on 17 Feb 2019  路  19Comments  路  Source: jhipster/generator-jhipster

Overview of the feature request

I have a strong incentive of adding Redis support to JHipster (we have a Prod project on PCF which absolutely need it in the next weeks), however, would you prefer it in the main gen, module or blueprint?

Side question: I noticed JH doesn't generate @Cacheable, @Cacheput and so on for CRUD: I may also add support for these annotation (but it's a mid term feature).

Motivation for or Use Case

An Onprem + SaaS microservice architecture with data sync between them: a Rabbit and Redis combination could be a way to help in this case.

Related issues or PR

7503

7691

1149

  • [x] Checking this box is mandatory (this is just to show you read everything)
$$ bug-bounty $$ $200 area good first issue java

Most helpful comment

I am quite interested, can I work on it ?

All 19 comments

I vote for module

Normally this should be a module, but as we already have Kafka, Cassandra, etc into the main generator that doesn't seem really fair to Redis.

Can this be a "simple" integration like Kafka: not too many files, and the minimum (or nothing at all) on the client side? This is to lower the maintenance burden.

I just wanted to use it as cache, not as database!

So that's another question: would you prefer it as cache implementation or database, or both?

I think we would want to have the implementation for the cache. We already have Memcached support. I think Redis should work similarly to Memcached.

I'm really disappointed by what I see when diving into the detail:
The only client that is compatible with spring cache, hibernate level 2 and/or JCache is paid (and far from being free): https://redisson.pro/
Others free alternatives (https://lettuce.io, https://github.com/xetorthio/jedis) are only compatible with Spring Cache (nor hibernate 2nd level nor JCache) and Spring Data.
I thought a server solution could have a paid plan but I never thought a client driver could be!

Do we want to have @Cacheable / CacheEvict / CachePut annotations everywhere (and only valid for DTOs) to have Redis cache support? It would also be a benefit the ones who choose cache and not hibernate second-level. But that task is a bigger one.

I can also add the database support if there's a need, but as it is not my priority, it can take some time...

@PierreBesson did not noticed Memcached did the same (no hibernate level2, no JCache).
I'll try to implement this one first :-).

@Tcharl I would say it's okay not having the hibernate 2nd level cache backed by Redis. We don't have it for the memcached option as well. Also a hit to redis will imply a network round trip so maybe it's better to explicitely set all the caches through annotations.

OK indeed Redis should only be used as a Spring Cache, like Memcached. As Memcached is an option, and as I guess Redis would be very simple and not have any impact on other options, it would be fair to include it into the main generator. And as a side note, I also have a strong incentive to have it, like you @Tcharl !!

@jdubois @Tcharl : do one of you plan to code this feature ?

I definitely plan to do this soon

I was on it, but unfortunately I really busy ATM.
If it's on my side, do not expect it before the end of summer.

Hello,
Just came across this topic and wanted to leave a note regarding the 2nd level cache of Hibernate with Redis. We've implemented it in a couple of our projects generated with Jhipster and it works pretty based on the following dependency:

<dependency>
    <groupId>org.redisson</groupId>
    <artifactId>redisson-hibernate-53</artifactId>
    <version>3.10.7</version>
</dependency>

Then you need the following spring.jpa.properties:

hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.cache.region.factory_class: org.redisson.hibernate.RedissonRegionFactory
hibernate.cache.region_prefix: hibernate
hibernate.cache.use_structured_entries: true
hibernate.cache.redisson.config: config/redisson-dev.yml

For the redisson-dev.yml file I mention, you can find examples on Redisson's wiki.

I hope this can help.

@anthonyrichir this helps me tremendously!!! I can't believe I missed this project, and it has nearly 10K GitHub stars!!!!! To me this is a game changer, as it's far easier to have a distributed Redis cache than the other alternatives (please note I work for Azure, so we have Azure Redis Cache out of the box...).

@jdubois @Tcharl what should we do with this issue?

This is going to be a new caching option, hopefully with Hibernate (but not required).
I'll add a bug bounty to motivate people.

I am quite interested, can I work on it ?

@Shaolans yes of course! I'll test it on Azure

@jdubois I'm still wondering what are the reasons to use Redisson rather than the usual support from spring data redis as demonstrated here : programmerfriend/ultimateredis/config/CacheConfig.java (based on Lettuce it seems).

@PierreBesson the Hibernate support is my main interest

I'm increasing the bounty as it's a lot of work (jhipster lib, generator, documentation, JDL).
Some people need this so it deserves it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomj0101 picture tomj0101  路  3Comments

edvjacek picture edvjacek  路  3Comments

marcelinobadin picture marcelinobadin  路  3Comments

kaidohallik picture kaidohallik  路  3Comments

DanielFran picture DanielFran  路  3Comments