All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.misk.redis.RedisService.kt Maven / Gradle / Ivy

There is a newer version: 2024.09.17.200749-4708422
Show newest version
package misk.redis

import com.google.common.util.concurrent.AbstractIdleService
import jakarta.inject.Inject
import com.google.inject.Provider
import jakarta.inject.Singleton

/** Controls the connection lifecycle for Redis. */
@Singleton
class RedisService @Inject internal constructor(
  private val redisProvider: Provider
) : AbstractIdleService() {
  // We initialize the client in startUp because creating the client will connect it to Redis
  private lateinit var redis: Redis

  override fun startUp() {
    // Create the client and connect to the redis instance
    redis = redisProvider.get()
  }

  override fun shutDown() {
    if (::redis.isInitialized) {
      redis.close()
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy