debop / hibernate-redis

hibernate 2nd level cache privder using redis
Apache License 2.0
357 stars 184 forks source link

How to configure hibernate second level and spring cache the same redissonclient? #122

Open kutuni opened 6 years ago

kutuni commented 6 years ago

How to configure hibernate second level and spring cache the same redissonclient? My solution is access redissonClient after initialized SingletonRedisRegionFactory, than construct RedissonSpringCacheManager with redissonClient;

it can Programaticly like below (2 class)

public class XRedisFactory extends SingletonRedisRegionFactory { private static RedissonClient redissonClient = null; public CMRedisFactory(Properties props) { super(props); } public void start(SessionFactoryOptions options, Properties properties) throws CacheException { super.start(options, properties); redissonClient = super.redis.getRedisson(); } public static RedissonClient getRedissonClient() { return redissonClient; } }

public class XRedisClient extends RedissonSpringCacheManager { public XRedisClient() { super(XRedisFactory.getRedissonClient()); } }


is there any efficient way ? (whithout code)

ti3r commented 5 years ago

We had a similar problem, little difference is that we wanted to build a HealthIndicator for the client used in the region factory. We ended up creating a whole new client using the same Config object as the RegionFactory just to check the status. I'm planning on opening a PR to fix it. Maybe using final RedisCacheUtil class to store a reference to the client?

kutuni commented 5 years ago

It's good idea. I am waiting...