sedis icon indicating copy to clipboard operation
sedis copied to clipboard

simplifying code and make it more variable

Open kinocz opened this issue 10 years ago • 0 comments

Not sure if I'm right, but this might suit sedis better. Added SPool which takes as constructor parameter redis.client.util.Pool[Jedis], which is parent class of both:

class Pool(override val underlying: JedisPool) extends SPool(underlying){
}

class SentinelPool(override val underlying: JedisSentinelPool) extends SPool(underlying){
}

class SPool(val underlying: redis.clients.util.Pool[Jedis]) {
  def withClient[T](body: Dress.Wrap => T): T = {
    val jedis: Jedis = underlying.getResource
    try {
      body(Dress.up(jedis))
    } finally {
      jedis.close()
    }
  }

  def withJedisClient[T](body: Jedis => T): T = {
    val jedis: Jedis = underlying.getResource
    try {
      body(jedis)
    } finally {
      jedis.close()
    }
  }
}

not making pull request, since I'm not sure if your original code is intended.

kinocz avatar Sep 17 '15 19:09 kinocz