0

I am trying to force my redis client to timeout for testing purpose and I a fail to achieve so. I specify timeout to 2ms in my config and the set operation I perform takes > 2ms so why it does not timeout? Are these settings are kind of soft settings and not hard enforcement? I am using Jedis 2.6 and Scala 2.10 with Play 2.2.3

@Singleton
class RedisClient extends Cache {

  // set timeout
  val TIMEOUT = 2
  private val pool = new JedisPool(new JedisPoolConfig(), getStringFromConfig("redis.url"), getIntFromConfig("redis.port"), TIMEOUT);

  def isOpen = pool.getNumActive()

  def set(key: String, value: String) = {
    isOpen match {
      case -1 => throw new Exception("Redis server is not running")
      case _ => {
        val jedis = pool.getResource()
        val before = Platform.currentTime
        jedis.set(key, value)
        println("TIME TAKEN " + (Platform.currentTime - before))
        pool.returnResource(jedis)
      }
    }
  }
}
Richeek
  • 2,068
  • 2
  • 29
  • 37

1 Answers1

2

Actualy you do not need to test it but you may found answer in Jedis sources. TimeOut value used:

  • as java socket connection timeout
  • as SO_TIMEOUT value. More info about it here.

To achieve goal in your test:

  • Redis server should be heavy loaded during your test to not accept the connection. If you need connection timeout.
  • Try to use some proxy to drop down connection perfomance (timeout by SO_TIMEOUT value).
Community
  • 1
  • 1
Nick Bondarenko
  • 6,211
  • 4
  • 35
  • 56