Discord4J / Stores

A set of Discord entity cache implementations for Discord4J
https://discord4j.com
GNU Lesser General Public License v3.0
11 stars 7 forks source link

Lazily create Redis Client if none was set on Builder #12

Closed schnapster closed 3 years ago

schnapster commented 3 years ago

I usually get this warning at start, because I configure the client in the redis store manually:

2021-05-02 19:21:28.632 []  WARN 11160 --- [      Finalizer] i.l.c.resource.DefaultClientResources    : io.lettuce.core.resource.DefaultClientResources was not shut down properly, shutdown() was not called before it's garbage-collected. Call shutdown() or shutdown(long,long,TimeUnit) 
    private fun redisStoreService(): StoreService {
        val redisClient = RedisClient.create(databaseConfig.entityCacheRedisUrl)
        return RedisStoreService.builder()
            .redisClient(redisClient)
            .build()
    }

The Builder eagerly creates the default Redis Client, which gets overwritten by my custom one, which results in the above warning logged when eventually the defaut Redis Client is GCed. This PR changes the Builder to lazily create the default Redis Client when it actually builds the store and none has been set.