What is the "- +" in the redis timeseries commands?

279 Views Asked by At

I don't get the examples that have - + in the command. I'm probably missing something that is well-known and I'm just not aware/or know where to get the info but for example at https://redis.io/docs/stack/timeseries/quickstart/

They have command TS.RANGE sensor1 - + FILTER_BY_TS 1626435230501 1626443276598

but I don't get what the - + is. Does anyone know?

2

There are 2 best solutions below

3
On

TS.RANGE, TS.REVRANGE, TS.MRANGE, and TS.MREVRANGE are range commands. You need to specify the range start and end timestamps.

Instead of specifying concrete values, you can you - and + respectively.

RedisTimeSeries replaces - with the timestamp of the earliest sample in the time series, and + with the timestamp of the latest sample in the time series.

Note that the query you composed

TS.RANGE sensor1 - + FILTER_BY_TS 1626435230501 1626443276598

would report samples only for two specific timestamps: 1626435230501 and 1626443276598, as FILTER_BY_TS is used for specifying a set of exact timestamps - not a range (to retrieve results, you must have samples with these exact timestamps, and these timestamps must fall within [fromTimestamp .. toTimestamp] which is [- .. +] in your case).

If you want to retrieve all samples between timestamp 1626435230501 and timestamp 1626443276598, you should instead use

TS.RANGE sensor1 1626435230501 1626443276598

And if you want to retrieve all samples in the time series, you can use

TS.RANGE sensor1 - +
1
On

The command format is: TS.RANGE key fromTimestamp toTimestamp

From the doc:

fromTimestamp

is start timestamp for the range query. Use - to express the minimum possible timestamp (0).

toTimestamp

is end timestamp for the range query. Use + to express the maximum possible timestamp.

So in your case, it means DO NOT filter data by timestamp.