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

com.sksamuel.cohort.lettuce.RedisWarmup.kt Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package com.sksamuel.cohort.lettuce

import com.sksamuel.cohort.WarmupHealthCheck
import io.lettuce.core.api.StatefulRedisConnection
import kotlinx.coroutines.future.await
import kotlin.random.Random

@Deprecated("Use RedisConnectionWarmup")
class RedisWarmup(
   override val iterations: Int,
   private val conn: StatefulRedisConnection,
   private val command: suspend (StatefulRedisConnection) -> Unit,
) : WarmupHealthCheck() {

   companion object {

      operator fun  invoke(
         iterations: Int,
         conn: StatefulRedisConnection,
         genkey: () -> K
      ): RedisWarmup {
         return RedisWarmup(iterations, conn) { it.async().get(genkey()).await() }
      }

      operator fun invoke(iterations: Int, conn: StatefulRedisConnection): RedisWarmup {
         return RedisWarmup(iterations, conn) { it.async().get(Random.nextInt().toString()).await() }
      }
   }

   override val name: String = "redis_warmup"

   override suspend fun warm(iteration: Int) {
      command(conn)
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy