Skip to content

Commit

Permalink
add client trackinginfo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Cem Asma authored and Cem Asma committed Mar 1, 2024
1 parent 3dfa82d commit 03ee2c1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,19 @@ public String toString() {
}
};

public static final Builder<TrackingInfo> TRACKING_INFO_RESPONSE = new Builder<TrackingInfo>() {
@Override
public TrackingInfo build(Object data) {
if (data == null) {
return null;
}

List<Object> trackingInfo = (List<Object>) data;

return TrackingInfo.TRACKING_INFO_BUILDER.build(trackingInfo);
}
};

/**
* A decorator to implement Set from List. Assume that given List do not contains duplicated
* values. The resulting set displays the same ordering, concurrency, and performance
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,13 @@ public String clientNoTouchOff() {
return connection.getStatusCodeReply();
}

@Override
public TrackingInfo clientTrackingInfo() {
checkIsInMultiOrPipeline();
connection.sendCommand(CLIENT, "TRACKINGINFO");
return BuilderFactory.TRACKING_INFO_RESPONSE.build(connection.getOne());
}

public List<String> time() {
checkIsInMultiOrPipeline();
connection.sendCommand(Command.TIME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import redis.clients.jedis.args.ClientType;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.resps.TrackingInfo;

/**
* The interface contain all the commands about client.
Expand Down Expand Up @@ -170,4 +171,6 @@ public interface ClientCommands {
* @return OK
*/
String clientNoTouchOff();

TrackingInfo clientTrackingInfo();
}
47 changes: 47 additions & 0 deletions src/main/java/redis/clients/jedis/resps/TrackingInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package redis.clients.jedis.resps;

import redis.clients.jedis.Builder;

import java.util.List;

import static redis.clients.jedis.BuilderFactory.LONG;
import static redis.clients.jedis.BuilderFactory.STRING_LIST;

public class TrackingInfo {

private final List<String> flags;
private final long redirect;
private final List<String> prefixes;

public TrackingInfo(List<String> flags, long redirect, List<String> prefixes) {
this.flags = flags;
this.redirect = redirect;
this.prefixes = prefixes;
}


public List<String> getFlags() {
return flags;
}

public long getRedirect() {
return redirect;
}

public List<String> getPrefixes() {
return prefixes;
}

public static final Builder<TrackingInfo> TRACKING_INFO_BUILDER = new Builder<TrackingInfo>() {
@Override
public TrackingInfo build(Object data) {
List<Object> commandData = (List<Object>) data;

List<String> flags = STRING_LIST.build(commandData.get(1));
long redirect = LONG.build(commandData.get(3));
List<String> prefixes = STRING_LIST.build(commandData.get(5));

return new TrackingInfo(flags, redirect, prefixes);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.resps.TrackingInfo;

public class ClientCommandsTest extends JedisCommandsTestBase {

Expand Down Expand Up @@ -258,6 +259,16 @@ public void listWithType() {
assertEquals(1, client.clientList(ClientType.PUBSUB).split("\\n").length);
}

@Test
public void trackingInfo() {
TrackingInfo trackingInfo = client.clientTrackingInfo();

assertEquals(1, trackingInfo.getFlags().size());
assertEquals(-1, trackingInfo.getRedirect());
assertEquals(0, trackingInfo.getPrefixes().size());
System.out.println(trackingInfo);
}

private void assertDisconnected(Jedis j) {
try {
j.ping();
Expand Down

0 comments on commit 03ee2c1

Please sign in to comment.