0

We want to use the redisson-hibernate project https://github.com/redisson/redisson/tree/master/redisson-hibernate to support redis 2nd level cache.

I tested redisson-hibernate module in multiple containers by using same Redis database. We use same database in the same Redis. But it doesn't share same data. Java application in the first container doesn't see updates of the records made by Java application in the second container. Every Java application have own version of the records.

Does Redisson Hibernate Cache Module can share same data in multiple containers?

Our redisson.yaml file contents:

singleServerConfig:
  idleConnectionTimeout: 10000
  connectTimeout: 10000
  timeout: 3000
  retryAttempts: 3
  retryInterval: 1500
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  address: "redis://127.0.0.1:6380"
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 50
  connectionMinimumIdleSize: 24
  connectionPoolSize: 64
  database: 0
  dnsMonitoringInterval: 5000
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.FstCodec> {}
transportMode: "NIO"

We use hibernate for interacting with the postgresql database, it's our hibernate connection properties file contents:

hibernate.connection.url=jdbc:postgresql://localhost:5439/testdb
hibernate.connection.username=testdb
hibernate.connection.password=testdb567
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.pool_size=10
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory
hibernate.current_session_context_class=thread
hibernate.show_sql=true
hibernate.cache.region.factory_class=org.redisson.hibernate.RedissonRegionFactory
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.redisson.fallback=true
hibernate.cache.redisson.config=redisson.yaml

1 Answers1

0

Yes, it does. It's the purpose of the module.

Java application in the first container doesn't see updates of the records

You might connected to the same Redis but different database. If this option is defined.

Every Java application have own version of the records.

That's impossible in Redis.

Could you describe your application structure and Redis setup?

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
  • Nikita, thanks for your answer. But we use same database in the same Redis. If we issue command "INFO keyspace" in redis-cli, it returns "db0:keys=6,expires=0,avg_ttl=0". – Kuanyshbek Mar 11 '20 at 05:32
  • I added redisson.yaml file contents to the question. Also added hibernate connection properties file contents. – Kuanyshbek Mar 11 '20 at 05:47
  • You need to set `hibernate.cache.use_second_level_cache = true` and `hibernate.cache.use_query_cache = true`. Also please remove `hibernate.cache.provider_class` setting – Nikita Koksharov Mar 11 '20 at 06:55
  • I corrected hibernate properties file according to your recommendations, it works now. Two different containers see same data now. Thanks! But it works more slowly than without caching. Is it possible to increase performance? – Kuanyshbek Mar 16 '20 at 14:04
  • Check your Redis server and network performance. Also try to use compression codecs like SnappyCodec – Nikita Koksharov Mar 17 '20 at 09:03
  • Thanks! Ok, I will try it. – Kuanyshbek Mar 18 '20 at 12:48