Skip to content
Open
Changes from 5 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
49 changes: 13 additions & 36 deletions src/main/scala/sedis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ trait Dress {
}

def get(k: String): Option[String] = {
val f = j.get(k)
if (f == null) None else Some(f)
Option(j.get(k))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an unrelated fix, can you move it to another PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will send this as another PR!

}
def lrange(key: String, start: Long, end: Long): List[String] = {
j.lrange(key,start,end).asScala.toList
Expand Down Expand Up @@ -91,46 +90,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)

}