Skip to content

Commit

Permalink
Merge branch 'master' into stream-pipeline-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gerzse authored Mar 11, 2024
2 parents 47a406a + 2394380 commit e4dff4a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
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 TrackingInfo.TRACKING_INFO_BUILDER.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();
}
70 changes: 70 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,70 @@
package redis.clients.jedis.resps;

import redis.clients.jedis.Builder;
import redis.clients.jedis.util.KeyValue;

import java.util.Collections;
import java.util.List;

import static redis.clients.jedis.BuilderFactory.*;

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 commandData = (List) data;

if (commandData.get(0) instanceof KeyValue) {
List<String> flags = Collections.emptyList();
long redirect = -1;
List<String> prefixes = Collections.emptyList();

for (KeyValue kv : (List<KeyValue>) commandData) {
switch (STRING.build(kv.getKey())) {
case "flags":
flags = STRING_LIST.build(kv.getValue());
break;
case "redirect":
redirect = LONG.build(kv.getValue());
break;
case "prefixes":
prefixes = STRING_LIST.build(kv.getValue());
break;
}
}

return new TrackingInfo(flags, redirect, prefixes);
} else {
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 @@ -19,12 +19,15 @@
import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.RedisProtocol;
import redis.clients.jedis.args.ClientAttributeOption;
import redis.clients.jedis.args.ClientType;
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 @@ -279,6 +282,26 @@ 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());
}

@Test
public void trackingInfoResp3() {
Jedis clientResp3 = new Jedis(hnp, DefaultJedisClientConfig.builder()
.protocol(RedisProtocol.RESP3).password("foobared").build());
TrackingInfo trackingInfo = clientResp3.clientTrackingInfo();

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

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

0 comments on commit e4dff4a

Please sign in to comment.