Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear cached InetSocketAddress on reconnect. #59

Merged
merged 1 commit into from
Oct 15, 2014
Merged
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
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