Skip to content

Commit

Permalink
SentinelMonitored improvement: query all sentinels for master address…
Browse files Browse the repository at this point in the history
…, instead of just the first one
  • Loading branch information
tovbinm committed Sep 9, 2013
1 parent fe6db9c commit 731948a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/scala/redis/Redis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ abstract class SentinelMonitored(system: ActorSystem) {
def withMasterAddr[T](initFunction: (String, Int) => T): T = {
import scala.concurrent.duration._

val f = sentinelClients.head.getMasterAddr(master) map {
case Some((ip: String, port: Int)) => initFunction(ip, port)
case _ => throw new Exception(s"No such master '$master'")
}
Await.result(f, 15 seconds)
val f = sentinelClients.map(_.getMasterAddr(master))
val ff = Future.find(f) { case Some((_: String, _: Int)) => true case _ => false }
.map {
case Some(Some((ip: String, port: Int))) => initFunction(ip, port)
case _ => throw new Exception(s"No such master '$master'")
}

Await.result(ff, 15 seconds)
}
}

Expand Down

0 comments on commit 731948a

Please # to comment.