0

I have a multi-module maven application built with SpringBoot and hibernate in which I am trying to connect to a local Redis instance. I have 2 problems to solve: The issue of the open connections when initializing the project and secondly the problem that is writing and deleting the record in redis when making a query.

The class for the redis client:

public class KtpKtlRedisApplication {

    @Bean(destroyMethod = "shutdown")
    RedissonClient redissonDev(@Value("classpath:/redisson.yaml") Resource configFile) {
        try {

            Config config = Config.fromYAML(configFile.getInputStream());
            return Redisson.create(config);
        } catch (IOException e) {
            // TODO: handle exception
            return null;
        }
    }


    @Bean
    CacheManager cacheManager(RedissonClient redissonClient) {
        try {
            Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();
            config.put("cacheRedis", new CacheConfig(10 * 1 * 1000, 10 * 1 * 1000));
            return new RedissonSpringCacheManager(redissonClient, config);
        } catch (Exception e) {
            return null;
        }
    }

}

Entity mapping is done using xml files:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping
    package="cl.clave.kntpas.commonelements.commonclasses">
    <class discriminator-value="Parameter"
        name="cl.clave.kntpas.entity.commonelements.commonclasses.Parameter"
        table="parameter" polymorphism="explicit">
        <cache region= "parameterCache" usage="read-write"/>
        <id column="par_nparameterid" name="parameterIdentifierPar" type="long">
            <generator class="sequence">
                <param name="sequence">parameter_parameterid_sec</param>
            </generator>
        </id>
        <discriminator column="imo_sdiscriminator" force="false"
            insert="true" not-null="true" />
        <property column="par_sname" generated="never" lazy="false"
            name="namePar" type="string" update="true" />
        <property column="par_nupdateableind" generated="never" lazy="false"
            name="updateableIndicatorPar" type="boolean" update="true" />
...
    </class>
</hibernate-mapping>

redisson.yaml:

singleServerConfig:
  idleConnectionTimeout: 10000
  connectTimeout: 10000
  timeout: 3000
  retryAttempts: 3
  retryInterval: 1500
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  address: redis://127.0.0.1:6379
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 50
  connectionMinimumIdleSize: 10
  connectionPoolSize: 64
  database: 0
  dnsMonitoringInterval: 5000

The libraries and versions used:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.5.4</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.5.7.Final</version>
</dependency>
<dependency>
  <groupId>org.redisson</groupId>
  <artifactId>redisson-hibernate-53</artifactId>
  <version>3.23.1</version>
</dependency>

The first drawback I find is that deploying the project initializes 10 connections to the redis server.

I show the log:

2023-08-10 08:13:01.755 INFO 6796 --- [ main] org.redisson.Version : Redisson 3.23.1 2023-08-10 08:13:01.791 DEBUG 6796 --- [isson-netty-5-2] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.793 DEBUG 6796 --- [isson-netty-5-3] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.805 DEBUG 6796 --- [isson-netty-5-4] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@941880165 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0xf68240c7, L:/127.0.0.1:60252 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.806 DEBUG 6796 --- [isson-netty-5-5] o.r.connection.ClientConnectionsEntry : new pubsub connection created: RedisPubSubConnection@1736607246 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x2d0180e5, L:/127.0.0.1:60253 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.806 INFO 6796 --- [isson-netty-5-5] o.r.c.pool.MasterPubSubConnectionPool : 1 connections initialized for 127.0.0.1/127.0.0.1:6379 2023-08-10 08:13:01.809 DEBUG 6796 --- [isson-netty-5-6] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.816 DEBUG 6796 --- [isson-netty-5-7] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@1737045737 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x663ea276, L:/127.0.0.1:60254 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.819 DEBUG 6796 --- [isson-netty-5-8] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.826 DEBUG 6796 --- [isson-netty-5-9] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@1654241293 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0xc1c858f8, L:/127.0.0.1:60255 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.833 DEBUG 6796 --- [sson-netty-5-10] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.841 DEBUG 6796 --- [sson-netty-5-11] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@514752106 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x01d7ecfd, L:/127.0.0.1:60256 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.845 DEBUG 6796 --- [sson-netty-5-12] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.854 DEBUG 6796 --- [sson-netty-5-13] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@1548100516 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0xe9f1aa89, L:/127.0.0.1:60257 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.860 DEBUG 6796 --- [sson-netty-5-14] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.869 DEBUG 6796 --- [sson-netty-5-15] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@2142829250 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x5fca52a8, L:/127.0.0.1:60258 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.875 DEBUG 6796 --- [sson-netty-5-16] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.884 DEBUG 6796 --- [sson-netty-5-17] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@161266743 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x5fe67324, L:/127.0.0.1:60259 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.890 DEBUG 6796 --- [sson-netty-5-18] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.901 DEBUG 6796 --- [sson-netty-5-19] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@2013630900 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x078226a7, L:/127.0.0.1:60260 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.905 DEBUG 6796 --- [sson-netty-5-20] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.911 DEBUG 6796 --- [sson-netty-5-21] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@1204189812 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0x9e0c51b5, L:/127.0.0.1:60261 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.916 DEBUG 6796 --- [sson-netty-5-22] org.redisson.client.RedisConnection : Connection created [addr=redis://127.0.0.1:6379] 2023-08-10 08:13:01.921 DEBUG 6796 --- [sson-netty-5-23] o.r.connection.ClientConnectionsEntry : new connection created: RedisConnection@339142860 [redisClient=[addr=redis://127.0.0.1:6379], channel=[id: 0xc6e39469, L:/127.0.0.1:60262 - R:127.0.0.1/127.0.0.1:6379], currentCommand=null, usage=0] 2023-08-10 08:13:01.921 INFO 6796 --- [sson-netty-5-23] o.r.c.pool.MasterConnectionPool : 10 connections initialized for 127.0.0.1/127.0.0.1:6379 2023-08-10 08:13:03.580 INFO 6796 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8084 (http) with context path ''

Then when I execute a search query, in the logs I see that it writes to Redis but at the same time it deletes the written record; All at the same time.

I show the logs: 1691673465.194274 [0 lua] "hget" "parameterCache" "\x01\x00org.hibernate.cache.internal.CacheKeyImplementatio\xee\xbecl.clave.kntpas.entity.commonelements.commonclasses.Parameter\xeep\t\xd2\x03\x80\x01\x01org.hibernate.type.LongTyp\xe5\x01\x02org.hibernate.engine.jdbc.Siz\xe5\xfe\x03\x01&\x04\x01\x03org.hibernate.type.descriptor.java.LongTypeDescripto\xf2\x01\x04org.hibernate.internal.util.compare.ComparableComparato\xf2\x01\x05org.hibernate.type.descriptor.java.ImmutableMutabilityPla\xee\t\x00\x01\x06org.hibernate.type.descriptor.sql.BigIntTypeDescripto\xf2\x02\t" 1691673465.194391 [0 lua] "hset" "parameterCache" "\x01\x00org.hibernate.cache.internal.CacheKeyImplementatio\xee\xbecl.clave.kntpas.entity.commonelements.commonclasses.Parameter\xeep\t\xd2\x03\x80\x01\x01org.hibernate.type.LongTyp\xe5\x01\x02org.hibernate.engine.jdbc.Siz\xe5\xfe\x03\x01&\x04\x01\x03org.hibernate.type.descriptor.java.LongTypeDescripto\xf2\x01\x04org.hibernate.internal.util.compare.ComparableComparato\xf2\x01\x05org.hibernate.type.descriptor.java.ImmutableMutabilityPla\xee\t\x00\x01\x06org.hibernate.type.descriptor.sql.BigIntTypeDescripto\xf2\x02\t" "\x00\x00\x00\x00\x00\x00\x00\x00\xd6\x01\x00\x00\x00\x00\x00\x00\x01\x00org.hibernate.cache.spi.support.AbstractReadWriteAccess$Ite\xed\x80\xc0\xe6\x90\xb1\xfe\xce\x18\x01\x01org.hibernate.cache.spi.entry.StandardCacheEntryImp\xec\x01\x02[Ljava.io.Serializable\xbb\x0e\x03extractDateStar\xf4\x05\x00\x01\x03cl.clave.kntpas.entity.commonelements.commoncodelists.DataTypeCodeLis\xf4\x01\x0318-12-201\xb9\t\xee\x03\t\xa4\xb8\x05\x03Paramete\xf2\x01\x04cl.clave.kntpas.entity.commonelements.commoncodelists.DataCompleteCodeLis\xf4\x01\x01\x05java.sql.Timestam\xf0\x80\x8e\xd4\x9a\xf3-\x0316608427-\xcb\x03\x821\x01\x05\x80\x8e\xd4\x9a\xf3-\x0316608427-\xcb\xbecl.clave.kntpas.entity.commonelements.commonclasses.Parameter\x00\x00" 1691673465.194656 [0 lua] "hget" "{parameterCache}:redisson_options" "has-listeners" 1691673465.194687 [0 lua] "hget" "{parameterCache}:redisson_options" "max-size" 1691673465.239875 [0 127.0.0.1:49166] "DEL" "parameterCache" "redisson__timeout__set:{parameterCache}" "redisson__idle__set:{parameterCache}" "redisson__map_cache__last_access__set:{parameterCache}"

I was expecting the entities to be stored in redis correctly, however when performing a search filtering by the id in the logs I find that the entity is stored in redis but in the same execution it is removed from redis.

0 Answers0