Skip to content

Commit

Permalink
Merge pull request #59 from SpinGo/bust-cache
Browse files Browse the repository at this point in the history
Clear cached InetSocketAddress on reconnect.
  • Loading branch information
etaty committed Oct 15, 2014
2 parents b5f1769 + 31a2394 commit 3741e1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main/scala/redis/Redis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ abstract class RedisClientActorLike(system: ActorRefFactory) extends ActorReques
)

def reconnect(host: String = host, port: Int = port) = {
if (this.host != host || this.port != port) {
this.host = host
this.port = port
redisConnection ! new InetSocketAddress(host, port)
}
this.host = host
this.port = port
redisConnection ! new InetSocketAddress(host, port)
}

def onConnect(redis: RedisCommands): Unit = {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/redis/actors/RedisWorkerIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ abstract class RedisWorkerIO(val address: InetSocketAddress) extends Actor with
tcpWorker ! Close
}
log.info(s"Connect to $currAddress")
// Create a new InetSocketAddress to clear the cached IP address.
currAddress = new InetSocketAddress(currAddress.getHostName, currAddress.getPort)
tcp ! Connect(currAddress)
}

Expand Down
1 change: 1 addition & 0 deletions src/test/scala/redis/actors/RedisWorkerIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RedisWorkerIOSpec extends TestKit(ActorSystem()) with SpecificationLike wi
within(1 second, 4 seconds) {
val connectMsg = probeTcp.expectMsgType[Connect]
connectMsg mustEqual Connect(address)
connectMsg.remoteAddress must not beTheSameAs(address)

val probeTcpWorker = TestProbe()
probeTcpWorker.send(redisWorkerIO, Connected(connectMsg.remoteAddress, address))
Expand Down

0 comments on commit 3741e1f

Please sign in to comment.