From 731948a182601b28cc81618f1d6969cb4bb86067 Mon Sep 17 00:00:00 2001 From: Matthew Tovbin Date: Mon, 9 Sep 2013 14:43:48 -0700 Subject: [PATCH] SentinelMonitored improvement: query all sentinels for master address, instead of just the first one --- src/main/scala/redis/Redis.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/scala/redis/Redis.scala b/src/main/scala/redis/Redis.scala index 5db53982..d82a81a1 100644 --- a/src/main/scala/redis/Redis.scala +++ b/src/main/scala/redis/Redis.scala @@ -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) } }