0

I recently created a project using JHipster with Redis. I notice that the type of redis document it uses is hash.

@Configuration
@EnableCaching
public class CacheConfigurationExtended extends CacheConfiguration {

    @Bean
    public javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration(JHipsterProperties jHipsterProperties) {
        MutableConfiguration<Object, Object> jcacheConfig = new MutableConfiguration<>();
        Config config = new Config();
        if (jHipsterProperties.getCache().getRedis().isCluster()) {
            config.useClusterServers().addNodeAddress(jHipsterProperties.getCache().getRedis().getServer());
        } else {
            config.useSingleServer().setAddress(jHipsterProperties.getCache().getRedis().getServer()[0]);
        }
        jcacheConfig.setStatisticsEnabled(true);
        jcacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, jHipsterProperties.getCache().getRedis().getExpiration())));
        return RedissonConfiguration.fromInstance(Redisson.create(config), jcacheConfig);
    }

    @Bean
    public JCacheManagerCustomizer cacheManagerCustomizer(javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration) {
        return cm -> {
            createCache(cm, com.dsa.portal.repository.UserRepository.USERS_BY_LOGIN_CACHE, jcacheConfiguration);
            createCache(cm, com.dsa.portal.repository.UserRepository.USERS_BY_EMAIL_CACHE, jcacheConfiguration);
            createCache(cm, com.dsa.portal.domain.User.class.getName(), jcacheConfiguration);
            createCache(cm, com.dsa.portal.domain.Authority.class.getName(), jcacheConfiguration);
            createCache(cm, com.dsa.portal.domain.User.class.getName() + ".authorities", jcacheConfiguration);
            createCache(cm, com.dsa.portal.domain.News.class.getName(), jcacheConfiguration);
            // jhipster-needle-redis-add-entry
        };
    }

    private void createCache(javax.cache.CacheManager cm, String cacheName, javax.cache.configuration.Configuration<Object, Object> jcacheConfiguration) {
        javax.cache.Cache<Object, Object> cache = cm.getCache(cacheName);
        if (cache == null) {
            cm.createCache(cacheName, jcacheConfiguration);
        }
    }
}

How can I tell JHipster to use Sorted Set for lets say my News entity ?

abiieez
  • 3,139
  • 14
  • 57
  • 110

1 Answers1

0

You can use Redisson Java Client for Redis.

Integrate Redis to JHipster CacheConfiguration error

It is a high level client and has all Redis datastructures like scored sorted sets ,maps and lists.