Skip to content

Commit

Permalink
Do not cache InetSocketAddress/SocketAddress in RedisURI #144
Browse files Browse the repository at this point in the history
The SocketAddress obtained by getResolvedAddress is no longer cached. This is to allow dynamic DNS updates at the time of establishing a connection. This change introduces the possibility to change the Redis connection point details because the connection point details are obtained directly from the RedisURI argument.
  • Loading branch information
mp911de committed Oct 25, 2015
1 parent 144d1de commit 4fc6bbc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Enhancements

Fixes
-----
* Do not cache InetSocketAddress/SocketAddress in RedisURI #144

Other
------
Expand Down
18 changes: 3 additions & 15 deletions src/main/java/com/lambdaworks/redis/RedisURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public class RedisURI implements Serializable, ConnectionPoint {
private long timeout = 60;
private TimeUnit unit = TimeUnit.SECONDS;
private final List<RedisURI> sentinels = new ArrayList<RedisURI>();
private transient SocketAddress resolvedAddress;

/**
* Default empty constructor.
Expand Down Expand Up @@ -339,22 +338,11 @@ public List<RedisURI> getSentinels() {
* @return the resolved {@link SocketAddress} based either on host/port or the socket.
*/
public SocketAddress getResolvedAddress() {
if (resolvedAddress == null) {
resolveAddress();
}

return resolvedAddress;
}

/**
* Resolve the address.
*/
private void resolveAddress() {
if (getSocket() != null) {
resolvedAddress = EpollProvider.newSocketAddress(getSocket());
} else {
resolvedAddress = new InetSocketAddress(host, port);
return EpollProvider.newSocketAddress(getSocket());
}

return new InetSocketAddress(host, port);
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/lambdaworks/redis/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public void pingBeforeConnectFailOnReconnect() throws Exception {
assertThat(connectionWatchdog.isReconnectSuspended()).isFalse();

redisUri.setPort(TestSettings.nonexistentPort());
ReflectionTestUtils.setField(redisUri, "resolvedAddress", null);

connection.quit();
Wait.untilTrue(() -> connectionWatchdog.isReconnectSuspended()).waitOrTimeout();
Expand Down Expand Up @@ -248,7 +247,6 @@ public void cancelCommandsOnReconnectFailure() throws Exception {

connectionWatchdog.setReconnectSuspended(true);
redisUri.setPort(TestSettings.nonexistentPort());
ReflectionTestUtils.setField(redisUri, "resolvedAddress", null);

connection.quit();
Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
Expand Down

0 comments on commit 4fc6bbc

Please sign in to comment.