Skip to content

Commit 9803f89

Browse files
authored
Update XINFO STREAM reply (#3421)
with new active-time field and seen-time meaning.
1 parent 65d47fc commit 9803f89

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/main/java/redis/clients/jedis/BuilderFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,8 @@ public String toString() {
13121312
}
13131313
};
13141314

1315-
private static final Builder<List<StreamConsumerFullInfo>> STREAM_CONSUMER_FULL_INFO_LIST = new Builder<List<StreamConsumerFullInfo>>() {
1315+
private static final Builder<List<StreamConsumerFullInfo>> STREAM_CONSUMER_FULL_INFO_LIST
1316+
= new Builder<List<StreamConsumerFullInfo>>() {
13161317

13171318
final Map<String, Builder> mappingFunctions = createDecoderMap();
13181319

@@ -1340,7 +1341,8 @@ public List<StreamConsumerFullInfo> build(Object data) {
13401341
for (Object streamsEntry : streamsEntries) {
13411342
List<Object> consumerInfoList = (List<Object>) streamsEntry;
13421343
Iterator<Object> consumerInfoIterator = consumerInfoList.iterator();
1343-
StreamConsumerFullInfo consumerInfo = new StreamConsumerFullInfo(createMapFromDecodingFunctions(consumerInfoIterator, mappingFunctions));
1344+
StreamConsumerFullInfo consumerInfo = new StreamConsumerFullInfo(
1345+
createMapFromDecodingFunctions(consumerInfoIterator, mappingFunctions));
13441346
list.add(consumerInfo);
13451347
}
13461348
return list;
@@ -1352,7 +1354,8 @@ public String toString() {
13521354
}
13531355
};
13541356

1355-
private static final Builder<List<StreamGroupFullInfo>> STREAM_GROUP_FULL_INFO_LIST = new Builder<List<StreamGroupFullInfo>>() {
1357+
private static final Builder<List<StreamGroupFullInfo>> STREAM_GROUP_FULL_INFO_LIST
1358+
= new Builder<List<StreamGroupFullInfo>>() {
13561359

13571360
final Map<String, Builder> mappingFunctions = createDecoderMap();
13581361

@@ -1384,8 +1387,8 @@ public List<StreamGroupFullInfo> build(Object data) {
13841387

13851388
Iterator<Object> groupInfoIterator = groupInfo.iterator();
13861389

1387-
StreamGroupFullInfo groupFullInfo = new StreamGroupFullInfo(createMapFromDecodingFunctions(
1388-
groupInfoIterator, mappingFunctions));
1390+
StreamGroupFullInfo groupFullInfo = new StreamGroupFullInfo(
1391+
createMapFromDecodingFunctions(groupInfoIterator, mappingFunctions));
13891392
list.add(groupFullInfo);
13901393

13911394
}

src/main/java/redis/clients/jedis/resps/StreamConsumerFullInfo.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ public class StreamConsumerFullInfo implements Serializable {
1414

1515
public static final String NAME = "name";
1616
public static final String SEEN_TIME = "seen-time";
17+
public static final String ACTIVE_TIME = "active-time";
1718
public static final String PEL_COUNT = "pel-count";
1819
public static final String PENDING = "pending";
1920

2021
private final String name;
2122
private final Long seenTime;
23+
private final Long activeTime; // since Redis 7.2
2224
private final Long pelCount;
2325
private final List<List<Object>> pending;
2426
private final Map<String, Object> consumerInfo;
@@ -28,20 +30,29 @@ public StreamConsumerFullInfo(Map<String, Object> map) {
2830
consumerInfo = map;
2931
name = (String) map.get(NAME);
3032
seenTime = (Long) map.get(SEEN_TIME);
33+
activeTime = (Long) map.get(ACTIVE_TIME);
3134
pending = (List<List<Object>>) map.get(PENDING);
3235
pelCount = (Long) map.get(PEL_COUNT);
3336

34-
pending.stream().forEach(entry -> entry.set(0, new StreamEntryID((String) entry.get(0))));
37+
pending.forEach(entry -> entry.set(0, new StreamEntryID((String) entry.get(0))));
3538
}
3639

3740
public String getName() {
3841
return name;
3942
}
4043

44+
// TODO: Long
4145
public long getSeenTime() {
4246
return seenTime;
4347
}
4448

49+
/**
50+
* Since Redis 7.2.
51+
*/
52+
public Long getActiveTime() {
53+
return activeTime;
54+
}
55+
4556
public Long getPelCount() {
4657
return pelCount;
4758
}
@@ -50,6 +61,9 @@ public List<List<Object>> getPending() {
5061
return pending;
5162
}
5263

64+
/**
65+
* All data.
66+
*/
5367
public Map<String, Object> getConsumerInfo() {
5468
return consumerInfo;
5569
}

src/test/java/redis/clients/jedis/commands/jedis/StreamsCommandsTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.Map;
1919
import java.util.Map.Entry;
2020
import java.util.concurrent.atomic.AtomicReference;
21+
import org.hamcrest.MatcherAssert;
22+
import org.hamcrest.Matchers;
2123
import org.junit.Test;
2224

2325
import redis.clients.jedis.BuilderFactory;
@@ -917,6 +919,8 @@ public void xinfoStreamFullWithPending() {
917919
assertEquals(1, group.getConsumers().size());
918920
StreamConsumerFullInfo consumer = group.getConsumers().get(0);
919921
assertEquals("xreadGroup-consumer", consumer.getName());
922+
MatcherAssert.assertThat(consumer.getSeenTime(), Matchers.greaterThanOrEqualTo(0L));
923+
MatcherAssert.assertThat(consumer.getActiveTime(), Matchers.greaterThanOrEqualTo(0L));
920924
assertEquals(1, consumer.getPending().size());
921925
List<Object> consumerPendingEntry = consumer.getPending().get(0);
922926
assertEquals(id1, consumerPendingEntry.get(0));

0 commit comments

Comments
 (0)