Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 12 additions & 34 deletions src/main/scala/sedis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,24 @@ trait Dress {
}
object Dress extends Dress

abstract class AbstractPool {

def using[A <% java.io.Closeable, T](s: A)(f: A => T): T = try f(s) finally s.close()

class Pool(val underlying: JedisPool) {
}

def withClient[T](body: Dress.Wrap => T): T = {
val jedis: Jedis = underlying.getResource
try {
body(Dress.up(jedis))
} finally {
underlying.returnResourceObject(jedis)
}
}
def withJedisClient[T](body: Jedis => T): T = {
val jedis: Jedis = underlying.getResource
try {
body(jedis)
} finally {
underlying.returnResourceObject(jedis)
}
}
class Pool(val jedisPool: JedisPool) extends AbstractPool {

def withClient[T](body: Dress.Wrap => T): T = using(Dress.up(jedisPool.getResource))(body)

def withJedisClient[T](body: Jedis => T): T = using(jedisPool.getResource)(body)

}

class SentinelPool(val underlying: JedisSentinelPool) {
class SentinelPool(val jedisSentinelPool: JedisSentinelPool) extends AbstractPool {

def withClient[T](body: Dress.Wrap => T): T = {
val jedis: Jedis = underlying.getResource
try {
body(Dress.up(jedis))
} finally {
underlying.returnResourceObject(jedis)
}
}
def withJedisClient[T](body: Jedis => T): T = {
val jedis: Jedis = underlying.getResource
try {
body(jedis)
} finally {
underlying.returnResourceObject(jedis)
}
}
def withClient[T](body: Dress.Wrap => T): T = using(Dress.up(jedisSentinelPool.getResource))(body)

def withJedisClient[T](body: Jedis => T): T = using(jedisSentinelPool.getResource)(body)

}