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

Enrich the information returned by toString() of Connection #3745

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
Expand Down Expand Up @@ -37,6 +38,8 @@
private int soTimeout = 0;
private int infiniteSoTimeout = 0;
private boolean broken = false;
private boolean strValActive;
private String strVal;

public Connection() {
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
Expand Down Expand Up @@ -69,7 +72,42 @@

@Override
public String toString() {
return "Connection{" + socketFactory + "}";
if (strValActive == broken && strVal != null) {
return strVal;

Check warning on line 76 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L76

Added line #L76 was not covered by tests
}

int id = hashCode();
SocketAddress remoteAddr = socket.getRemoteSocketAddress();
SocketAddress localAddr = socket.getLocalSocketAddress();

Check warning on line 81 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L79-L81

Added lines #L79 - L81 were not covered by tests
if (remoteAddr != null) {
StringBuilder buf = new StringBuilder(96)
.append("[id: 0x")
.append(id)
.append(", L:")

Check warning on line 86 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L83-L86

Added lines #L83 - L86 were not covered by tests
.append(localAddr)
.append(broken? " ! " : " - ")
.append("R:")
.append(remoteAddr)
.append(']');
strVal = buf.toString();

Check warning on line 92 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L88-L92

Added lines #L88 - L92 were not covered by tests
} else if (localAddr != null) {
StringBuilder buf = new StringBuilder(64)
.append("[id: 0x")
.append(id)
.append(", L:")
.append(localAddr)
.append(']');
strVal = buf.toString();
} else {
StringBuilder buf = new StringBuilder(16)
.append("[id: 0x")
.append(id)
.append(']');
strVal = buf.toString();

Check warning on line 106 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L94-L106

Added lines #L94 - L106 were not covered by tests
}

strValActive = broken;
return strVal;

Check warning on line 110 in src/main/java/redis/clients/jedis/Connection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/redis/clients/jedis/Connection.java#L109-L110

Added lines #L109 - L110 were not covered by tests
}

public final RedisProtocol getRedisProtocol() {
Expand Down