Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ project/plugins/target
project/plugins/project/*
.idea/*
logs/
*iml
25 changes: 14 additions & 11 deletions src/main/scala/sedis.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.sedis

import redis.clients.jedis._
import scala.util.{Failure, Try}
import redis.clients.jedis.exceptions.JedisConnectionException

trait Dress {
implicit def delegateToJedis(d: Wrap) = d.j
Expand Down Expand Up @@ -90,22 +92,23 @@ object Dress extends Dress
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)
}
withJedisClient({ jedis: Jedis => body(Dress.up(jedis)) })
}

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

result match {
case Failure(e:JedisConnectionException) => {
Copy link
Owner

Choose a reason for hiding this comment

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

this exception is not logged, so the client won't be aware of this event.

underlying.returnBrokenResource(jedis)
}
case _ => {
underlying.returnResource(jedis)
}
}
result.get
Copy link
Owner

Choose a reason for hiding this comment

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

}

Choose a reason for hiding this comment

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

It's almost same as withJedisClient. Better to write as withJedisClient(jedis => body(Dress.up(jedis))).


}

class SentinelPool(val underlying: JedisSentinelPool) {
Expand Down