Visitar URL original
[Redis 8.10] Support TS.NRANGE and TS.NREVRANGE time series commands … · redis/jedis@bc93457 · GitHub
Skip to content

Commit bc93457

Browse files
authored
[Redis 8.10] Support TS.NRANGE and TS.NREVRANGE time series commands (#4650)
* - support TS.NRANGE and TS.NREVRANGE * - register RedisVersionCondition and EnableOnCommandCondition * remove experimental tag * remove experimental from ts.range * clean imports * remove experimental * use testkeyregistry * clenaup with TestKeyRegistry * revisit NRANGE params * add nrange/nrevrange as cacheable
1 parent e436088 commit bc93457

15 files changed

Lines changed: 1153 additions & 0 deletions

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@
528528
<!-- Specific files -->
529529
<include>src/main/java/redis/clients/jedis/annots/*.java</include>
530530
<include>src/main/java/redis/clients/jedis/params/XCfgSetParams.java</include>
531+
<include>src/main/java/redis/clients/jedis/timeseries/TSNRangeParams.java</include>
531532
<include>src/main/java/redis/clients/jedis/resps/StreamEntryDeletionResult.java</include>
532533
<include>src/main/java/redis/clients/jedisargs/StreamDeletionPolicy.java</include>
533534
<include>src/test/java/redis/clients/jedis/commands/StreamsCommandsTestBase.java</include>

‎src/main/java/redis/clients/jedis/CommandObjects.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,6 +4684,42 @@ public final CommandObject<List<TSElement>> tsRead(String key, TSReadParams read
46844684
return new CommandObject<>(args, TimeSeriesBuilderFactory.TIMESERIES_ELEMENT_LIST);
46854685
}
46864686

4687+
public final CommandObject<List<TSElement>> tsNRange(String[] keys, long fromTimestamp, long toTimestamp) {
4688+
checkNRangeKeys(keys);
4689+
return new CommandObject<>(commandArguments(TimeSeriesCommand.NRANGE).add(keys.length)
4690+
.keys((Object[]) keys).add(fromTimestamp).add(toTimestamp),
4691+
TimeSeriesBuilderFactory.TIMESERIES_PIVOT_ELEMENT_LIST);
4692+
}
4693+
4694+
public final CommandObject<List<TSElement>> tsNRange(String[] keys, TSNRangeParams nrangeParams) {
4695+
checkNRangeKeys(keys);
4696+
nrangeParams.validateAggregationForKeys(keys.length);
4697+
return new CommandObject<>(commandArguments(TimeSeriesCommand.NRANGE).add(keys.length)
4698+
.keys((Object[]) keys).addParams(nrangeParams),
4699+
TimeSeriesBuilderFactory.TIMESERIES_PIVOT_ELEMENT_LIST);
4700+
}
4701+
4702+
public final CommandObject<List<TSElement>> tsNRevRange(String[] keys, long fromTimestamp, long toTimestamp) {
4703+
checkNRangeKeys(keys);
4704+
return new CommandObject<>(commandArguments(TimeSeriesCommand.NREVRANGE).add(keys.length)
4705+
.keys((Object[]) keys).add(fromTimestamp).add(toTimestamp),
4706+
TimeSeriesBuilderFactory.TIMESERIES_PIVOT_ELEMENT_LIST);
4707+
}
4708+
4709+
public final CommandObject<List<TSElement>> tsNRevRange(String[] keys, TSNRangeParams nrangeParams) {
4710+
checkNRangeKeys(keys);
4711+
nrangeParams.validateAggregationForKeys(keys.length);
4712+
return new CommandObject<>(commandArguments(TimeSeriesCommand.NREVRANGE).add(keys.length)
4713+
.keys((Object[]) keys).addParams(nrangeParams),
4714+
TimeSeriesBuilderFactory.TIMESERIES_PIVOT_ELEMENT_LIST);
4715+
}
4716+
4717+
private static void checkNRangeKeys(String[] keys) {
4718+
if (keys == null || keys.length == 0) {
4719+
throw new IllegalArgumentException("TS.NRANGE/TS.NREVRANGE require at least one key");
4720+
}
4721+
}
4722+
46874723
public final CommandObject<Map<String, TSMRangeElements>> tsMRange(long fromTimestamp, long toTimestamp, String... filters) {
46884724
return new CommandObject<>(commandArguments(TimeSeriesCommand.MRANGE).add(fromTimestamp)
46894725
.add(toTimestamp).add(TimeSeriesKeyword.FILTER).addObjects((Object[]) filters),

‎src/main/java/redis/clients/jedis/PipeliningBase.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,26 @@ public Response<List<TSElement>> tsRead(String key, TSReadParams readParams) {
46874687
return appendCommand(commandObjects.tsRead(key, readParams));
46884688
}
46894689

4690+
@Override
4691+
public Response<List<TSElement>> tsNRange(String[] keys, long fromTimestamp, long toTimestamp) {
4692+
return appendCommand(commandObjects.tsNRange(keys, fromTimestamp, toTimestamp));
4693+
}
4694+
4695+
@Override
4696+
public Response<List<TSElement>> tsNRange(String[] keys, TSNRangeParams nrangeParams) {
4697+
return appendCommand(commandObjects.tsNRange(keys, nrangeParams));
4698+
}
4699+
4700+
@Override
4701+
public Response<List<TSElement>> tsNRevRange(String[] keys, long fromTimestamp, long toTimestamp) {
4702+
return appendCommand(commandObjects.tsNRevRange(keys, fromTimestamp, toTimestamp));
4703+
}
4704+
4705+
@Override
4706+
public Response<List<TSElement>> tsNRevRange(String[] keys, TSNRangeParams nrangeParams) {
4707+
return appendCommand(commandObjects.tsNRevRange(keys, nrangeParams));
4708+
}
4709+
46904710
@Override
46914711
public Response<Map<String, TSMRangeElements>> tsMRange(long fromTimestamp, long toTimestamp, String... filters) {
46924712
return appendCommand(commandObjects.tsMRange(fromTimestamp, toTimestamp, filters));

‎src/main/java/redis/clients/jedis/UnifiedJedis.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,6 +5468,26 @@ public List<TSElement> tsRead(String key, TSReadParams readParams) {
54685468
return executeCommand(commandObjects.tsRead(key, readParams));
54695469
}
54705470

5471+
@Override
5472+
public List<TSElement> tsNRange(String[] keys, long fromTimestamp, long toTimestamp) {
5473+
return executeCommand(commandObjects.tsNRange(keys, fromTimestamp, toTimestamp));
5474+
}
5475+
5476+
@Override
5477+
public List<TSElement> tsNRange(String[] keys, TSNRangeParams nrangeParams) {
5478+
return executeCommand(commandObjects.tsNRange(keys, nrangeParams));
5479+
}
5480+
5481+
@Override
5482+
public List<TSElement> tsNRevRange(String[] keys, long fromTimestamp, long toTimestamp) {
5483+
return executeCommand(commandObjects.tsNRevRange(keys, fromTimestamp, toTimestamp));
5484+
}
5485+
5486+
@Override
5487+
public List<TSElement> tsNRevRange(String[] keys, TSNRangeParams nrangeParams) {
5488+
return executeCommand(commandObjects.tsNRevRange(keys, nrangeParams));
5489+
}
5490+
54715491
@Override
54725492
public Map<String, TSMRangeElements> tsMRange(long fromTimestamp, long toTimestamp, String... filters) {
54735493
return executeCommand(commandObjects.tsMRange(fromTimestamp, toTimestamp, filters));

‎src/main/java/redis/clients/jedis/csc/DefaultCacheable.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class DefaultCacheable implements Cacheable {
6363
add(TimeSeriesCommand.INFO);
6464
add(TimeSeriesCommand.RANGE);
6565
add(TimeSeriesCommand.REVRANGE);
66+
add(TimeSeriesCommand.NRANGE);
67+
add(TimeSeriesCommand.NREVRANGE);
6668
add(Command.TYPE);
6769
add(Command.XLEN);
6870
add(Command.XPENDING);

‎src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesCommands.java‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,79 @@ public interface RedisTimeSeriesCommands {
213213
*/
214214
List<TSElement> tsRead(String key, TSReadParams readParams);
215215

216+
/**
217+
* <b><a href="https://redis.io/commands/ts.nrange">TS.NRANGE Command</a></b>
218+
* <p>
219+
* Queries an explicit list of time series over a timestamp range and returns a timestamp-major
220+
* response in forward (increasing timestamp) order. Each returned {@link TSElement} carries one
221+
* value per key, in the order the keys were passed; a key with no sample at a row timestamp is
222+
* surfaced as {@code NaN} (indistinguishable from a stored or aggregated {@code NaN}). Key order
223+
* and duplicate keys are significant and are preserved.
224+
* <p>
225+
* All keys must map to the same hash slot in a cluster; this is treated as a single-shard,
226+
* key-routed command and is not split across shards.
227+
* <p>
228+
* Time complexity: O(numkeys*(n/m+k)) where n = number of samples, m = chunk size, k = number of
229+
* samples in the requested range.
230+
*
231+
* @param keys explicit time series keys, in output column order (duplicates allowed)
232+
* @param fromTimestamp inclusive range start
233+
* @param toTimestamp inclusive range end
234+
* @return one pivot row per distinct timestamp, in increasing-timestamp order
235+
* @since 8.0
236+
*/
237+
List<TSElement> tsNRange(String[] keys, long fromTimestamp, long toTimestamp);
238+
239+
/**
240+
* <b><a href="https://redis.io/commands/ts.nrange">TS.NRANGE Command</a></b>
241+
* <p>
242+
* {@code TS.NRANGE numkeys key [key ...] fromTimestamp toTimestamp
243+
* [LATEST]
244+
* [FILTER_BY_TS ts...]
245+
* [FILTER_BY_VALUE min max]
246+
* [COUNT count]
247+
* [[ALIGN align] AGGREGATION aggregator [aggregator ...] bucketDuration [BUCKETTIMESTAMP bt] [EMPTY]]}
248+
* <p>
249+
* In aggregation mode exactly one aggregator token is emitted per key (see
250+
* {@link TSNRangeParams#aggregation(AggregationType[], long)} and
251+
* {@link TSNRangeParams#aggregation(AggregationType[][], long)}); the server rejects a mismatch
252+
* between the number of aggregator tokens and {@code numkeys}. Missing raw samples and missing
253+
* aggregation buckets are surfaced as {@code NaN}.
254+
*
255+
* @param keys explicit time series keys, in output column order (duplicates allowed)
256+
* @param nrangeParams optional range arguments (including {@code fromTimestamp}/{@code toTimestamp})
257+
* @return one pivot row per distinct timestamp, in increasing-timestamp order
258+
* @since 8.0
259+
*/
260+
List<TSElement> tsNRange(String[] keys, TSNRangeParams nrangeParams);
261+
262+
/**
263+
* <b><a href="https://redis.io/commands/ts.nrevrange">TS.NREVRANGE Command</a></b>
264+
* <p>
265+
* Reverse variant of {@link #tsNRange(String[], long, long)}: identical semantics but rows are
266+
* returned in decreasing-timestamp order. Server-returned order is preserved as-is.
267+
*
268+
* @param keys explicit time series keys, in output column order (duplicates allowed)
269+
* @param fromTimestamp inclusive range start
270+
* @param toTimestamp inclusive range end
271+
* @return one pivot row per distinct timestamp, in decreasing-timestamp order
272+
* @since 8.0
273+
*/
274+
List<TSElement> tsNRevRange(String[] keys, long fromTimestamp, long toTimestamp);
275+
276+
/**
277+
* <b><a href="https://redis.io/commands/ts.nrevrange">TS.NREVRANGE Command</a></b>
278+
* <p>
279+
* Reverse variant of {@link #tsNRange(String[], TSNRangeParams)}: identical semantics and options
280+
* but rows are returned in decreasing-timestamp order. Server-returned order is preserved as-is.
281+
*
282+
* @param keys explicit time series keys, in output column order (duplicates allowed)
283+
* @param nrangeParams optional range arguments (including {@code fromTimestamp}/{@code toTimestamp})
284+
* @return one pivot row per distinct timestamp, in decreasing-timestamp order
285+
* @since 8.0
286+
*/
287+
List<TSElement> tsNRevRange(String[] keys, TSNRangeParams nrangeParams);
288+
216289
/**
217290
* {@code TS.MRANGE fromTimestamp toTimestamp FILTER filter...}
218291
*

‎src/main/java/redis/clients/jedis/timeseries/RedisTimeSeriesPipelineCommands.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ public interface RedisTimeSeriesPipelineCommands {
4949

5050
Response<List<TSElement>> tsRead(String key, TSReadParams readParams);
5151

52+
/**
53+
* Pipeline variant of {@link RedisTimeSeriesCommands#tsNRange(String[], long, long)}.
54+
* @since 8.0
55+
*/
56+
Response<List<TSElement>> tsNRange(String[] keys, long fromTimestamp, long toTimestamp);
57+
58+
/**
59+
* Pipeline variant of {@link RedisTimeSeriesCommands#tsNRange(String[], TSNRangeParams)}.
60+
* @since 8.0
61+
*/
62+
Response<List<TSElement>> tsNRange(String[] keys, TSNRangeParams nrangeParams);
63+
64+
/**
65+
* Pipeline variant of {@link RedisTimeSeriesCommands#tsNRevRange(String[], long, long)}.
66+
* @since 8.0
67+
*/
68+
Response<List<TSElement>> tsNRevRange(String[] keys, long fromTimestamp, long toTimestamp);
69+
70+
/**
71+
* Pipeline variant of {@link RedisTimeSeriesCommands#tsNRevRange(String[], TSNRangeParams)}.
72+
* @since 8.0
73+
*/
74+
Response<List<TSElement>> tsNRevRange(String[] keys, TSNRangeParams nrangeParams);
75+
5276
Response<Map<String, TSMRangeElements>> tsMRange(long fromTimestamp, long toTimestamp, String... filters);
5377

5478
Response<Map<String, TSMRangeElements>> tsMRange(TSMRangeParams multiRangeParams);

0 commit comments

Comments
 (0)