Giter VIP home page Giter VIP logo

jredistimeseries's Introduction

Release CircleCI Dockerhub codecov

RedisTimeSeries

Forum Discord

logo

RedisTimeSeries is a time-series database (TSDB) module for Redis, by Redis.

RedisTimeSeries can hold multiple time series. Each time series is accessible via a single Redis key (similar to any other Redis data structure).

What is a Redis time series?

A Redis time series comprises:

  • Raw samples: each raw sample is a {time tag, value} pair.

    • Time tags are measured in milliseconds since January 1st, 1970, at 00:00:00.

      Time tags can be specified by the client or filled automatically by the server.

    • 64-bit floating-point values.

    The intervals between time tags can be constant or variable.

    Raw samples can be reported in-order or out-of-order.

    Duplication policy for samples with identical time tags can be set: block/first/last/min/max/sum.

  • An optional configurable retention period.

    Raw samples older than the retention period (relative to the raw sample with the highest time tag) are discarded.

  • Series Metadata: a set of name-value pairs (e.g., room = 3; sensorType = ‘xyz’).

    RedisTimeSeries supports cross-time-series commands. One can, for example, aggregate data over all sensors in the same room or all sensors of the same type.

  • Zero or more compactions.

    Compactions are an economical way to retain historical data.

    Each compaction is defined by:

    • A timeframe. E.g., 10 minutes
    • An aggregator: min, max, sum, avg, …
    • An optional retention period. E.g., 10 year

    For example, the following compaction: {10 minutes; avg; 10 years} will store the average of the raw values measured in each 10-minutes time frame - for 10 years.

How do I Redis?

Learn for free at Redis University

Build faster with the Redis Launchpad

Try the Redis Cloud

Dive in developer tutorials

Join the Redis community

Work at Redis

Examples of time series

  • Sensor data: e.g., temperatures or fan velocity for a server in a server farm
  • Historical prices of a stock
  • Number of vehicles passing through a given road (count per 1-minute timeframes)

Features

  • High volume inserts, low latency reads
  • Query by start time and end-time
  • Aggregated queries (Min, Max, Avg, Sum, Range, Count, First, Last, STD.P, STD.S, Var.P, Var.S, twa) for any time bucket
  • Configurable maximum retention period
  • Compactions - automatically updated aggregated timeseries
  • Secondary index - each time series has labels (name-value pairs) which will allows to query by labels

Using with other tools metrics tools

In the RedisTimeSeries organization you can find projects that help you integrate RedisTimeSeries with other tools, including:

  1. Prometheus - read/write adapter to use RedisTimeSeries as backend db.
  2. Grafana - using the Redis Data Source.
  3. Telegraf
  4. StatsD, Graphite exports using graphite protocol.

RedisTimeSeries is part of Redis Stack.

Setup

You can either get RedisTimeSeries setup in a Docker container or on your own machine.

Docker

To quickly try out RedisTimeSeries, launch an instance using docker:

docker run -p 6379:6379 -it --rm redis/redis-stack-server:latest

Build it yourself

You can also build RedisTimeSeries on your own machine. Major Linux distributions as well as macOS are supported.

First step is to have Redis installed, of course. The following, for example, builds Redis on a clean Ubuntu docker image (docker pull ubuntu) or a clean Debian docker image (docker pull debian:stable):

mkdir ~/Redis
cd ~/Redis
apt-get update -y && apt-get upgrade -y
apt-get install -y wget make pkg-config build-essential
wget https://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make distclean
make
make install

Next, you should get the RedisTimeSeries repository from git and build it:

apt-get install -y git
cd ~/Redis
git clone --recursive https://github.com/RedisTimeSeries/RedisTimeSeries.git
cd RedisTimeSeries
./sbin/setup
bash -l
make

Then exit to exit bash.

Note: to get a specific version of RedisTimeSeries, e.g. 1.8.10, add -b v1.8.10 to the git clone command above.

Next, run make run -n and copy the full path of the RedisTimeSeries executable (e.g., /root/Redis/RedisTimeSeries/bin/linux-x64-release/redistimeseries.so).

Next, add RedisTimeSeries module to redis.conf, so Redis will load when started:

apt-get install -y vim
cd ~/Redis/redis-stable
vim redis.conf

Add: loadmodule /root/Redis/RedisTimeSeries/bin/linux-x64-release/redistimeseries.so under the MODULES section (use the full path copied above).

Save and exit vim (ESC :wq ENTER)

For more information about modules, go to the Redis official documentation.

Run

Run redis-server in the background and then redis-cli:

cd ~/Redis/redis-stable
redis-server redis.conf &
redis-cli

Give it a try

After you setup RedisTimeSeries, you can interact with it using redis-cli.

Here we'll create a time series representing sensor temperature measurements. After you create the time series, you can send temperature measurements. Then you can query the data for a time range on some aggregation rule.

With redis-cli

$ redis-cli
127.0.0.1:6379> TS.CREATE temperature:3:11 RETENTION 60 LABELS sensor_id 2 area_id 32
OK
127.0.0.1:6379> TS.ADD temperature:3:11 1548149181 30
OK
127.0.0.1:6379> TS.ADD temperature:3:11 1548149191 42
OK
127.0.0.1:6379>  TS.RANGE temperature:3:11 1548149180 1548149210 AGGREGATION avg 5
1) 1) (integer) 1548149180
   2) "30"
2) 1) (integer) 1548149190
   2) "42"

Client libraries

Some languages have client libraries that provide support for RedisTimeSeries commands:

Project Language License Author Stars Package Comment
jedis Java MIT Redis Stars Maven
redis-py Python MIT Redis Stars pypi
node-redis Node.js MIT Redis Stars npm
nredisstack .NET MIT Redis Stars nuget
redistimeseries-go Go Apache-2 Redis redistimeseries-go-stars GitHub
rueidis Go Apache-2 Rueian rueidis-stars GitHub
phpRedisTimeSeries PHP MIT Alessandro Balasco phpRedisTimeSeries-stars GitHub
redis-time-series JavaScript MIT Rafa Campoy redis-time-series-stars GitHub
redistimeseries-js JavaScript MIT Milos Nikolovski redistimeseries-js-stars GitHub
redis_ts Rust BSD-3 Thomas Profelt redis_ts-stars GitHub
redistimeseries Ruby MIT Eaden McKee redistimeseries-stars GitHub
redis-time-series Ruby MIT Matt Duszynski redis-time-series-rb-stars GitHub

Tests

The module includes a basic set of unit tests and integration tests.

Unit tests

To run all unit tests, follow these steps:

$ make unit_tests

Integration tests

Integration tests are based on RLTest, and specific setup parameters can be provided to configure tests. By default the tests will be ran for all common commands, and with variation of persistency and replication.

To run all integration tests in a Python virtualenv, follow these steps:

$ mkdir -p .env
$ virtualenv .env
$ source .env/bin/activate
$ pip install -r tests/flow/requirements.txt
$ make test

To understand what test options are available simply run:

$ make help

For example, to run the tests strictly desigined for TS.ADD command, follow these steps:

$ make test TEST=test_ts_add.py

Documentation

Read the docs at http://redistimeseries.io

Mailing List / Forum

Got questions? Feel free to ask at the RedisTimeSeries forum.

License

RedisTimeSeries is licensed under the Redis Source Available License 2.0 (RSALv2) or the Server Side Public License v1 (SSPLv1).

jredistimeseries's People

Contributors

chayim avatar dengliming avatar dependabot[bot] avatar felipecsl avatar filipecosta90 avatar gkorland avatar iojeffrey avatar sazzad16 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jredistimeseries's Issues

Support for username when connecting to a Redis instance

Another issue for use in production in my case, the constructors provided with the library does not allow passing a username for connecting to a Redis 6 instance whose connection is made with a username/password couple and not only a password.

Using `-` and `+` with range and mrange

I think it's more a question than an issue but it seems there is something that could be at least documented in the library documentation.

When you use range or mrange, the type for from and to parameters is long. My question is how to use the special characters - and + to respectively to express the minimum possible timestamp and the maximum possible timestamp.

I guess using 0 and a very large number should work the same but I thought it was worth creating an issue to at least improve the documentation.

Support initialization from a Redis connection String

This client library does not support initializing a client from a connection string or URI. For instance, in an app I am working on, I receive a Redis connection string as input. Due to the lack of support for such input in the client library, I have to parse the String by myself or change the way connection data are passed.

All libraries I know support passing a connection String to initialize a connection to a database. Adding support should be quite easy since the underlying Jedis library that is used supports the use case. If you agree to fix this issue, the main issue is whether you prefer to support a String, a URI, or both as input.

Support for DUPLICATE_POLICY on TS.CREATE and TS.ADD

As of RedisTimeseries >= 1.4 You can now add samples to a time series where the time of the sample is older than the newest sample in the series. Bundled with that, we now have a policy that will define handling of duplicate samples, and that needs to be supported on the client via the arguments [DUPLICATE_POLICY policy] on TS.CREATE and via [ON_DUPLICATE policy] on TS.ADD. The following are the possible policies:

  • BLOCK - an error will occur for any out of order sample
  • FIRST - ignore the new value
  • LAST - override with latest value
  • MIN - only override if the value is lower than the existing value
  • MAX - only override if the value is higher than the existing value

Further reference: documentation link

Add support for TS.DEL

TS.DEL

Delete data points for a given timeseries and interval range in the form of start and end delete timestamps.

The given timestamp interval is closed (inclusive), meaning start and end data points will also be deleted.

TS.DEL key fromTimestamp toTimestamp
  • key - Key name for timeseries
  • fromTimestamp - Start timestamp for the range deletion.
  • toTimestamp - End timestamp for the range deletion.

Complexity

TS.DEL complexity is O(n).

n = Number of data points that are in the requested range

Delete range of data points example

TS.DEL temperature:2:32 1548149180000 1548149183000

Flaky testIncDec test

This test is occasionally failing for me when running locally, seems flaky:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.redislabs.redistimeseries.RedisTimeSeriesTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tests run: 12, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.495 sec <<< FAILURE! - in com.redislabs.redistimeseries.RedisTimeSeriesTest
testIncDec(com.redislabs.redistimeseries.RedisTimeSeriesTest)  Time elapsed: 0.019 sec  <<< ERROR!
redis.clients.jedis.exceptions.JedisDataException: TSDB: for incrby/decrby, timestamp should be newer than the lastest one
	at com.redislabs.redistimeseries.RedisTimeSeriesTest.testIncDec(RedisTimeSeriesTest.java:322)


Results :

Tests in error:
  RedisTimeSeriesTest.testIncDec:322 » JedisData TSDB: for incrby/decrby, timest...

Tests run: 12, Failures: 0, Errors: 1, Skipped: 0

Support for database index

Hey currently JRedisTimeseries doesn't have support for choosing a Redis Database.

I get that since you can create a RedisTimeseries Object by passing a Jedis Pool, and you can only select a database index after using getResource() from the JedisPool, you might not be able to add a index from using that constructor. But is it possible to add an attribute to this class for selecting a database index?

TS Range multiple value buckets for aggregate .

I am using redis version 6.0.1 running via docker (docker run -p 6379:6379 -it --rm redislabs/redistimeseries)

I am trying to get an daily sum aggregate of values on a given key via:

rts.range(key, LocalDateTime.now().minusDays(1).toInstant(ZoneOffset.ofHours(2)).toEpochMilli(),LocalDateTime.now().toInstant(ZoneOffset.ofHours(2)).toEpochMilli(), Aggregation.SUM, 863400000);

The result is an array having 2 values. This is different from running the same TS.RANGE command directly via redis which will produce only a single data value.

Below screenshot shows values in intelij
84792605-561f6300-aff4-11ea-8546-b889f08499f0

result in redisinsight
84792754-8b2bb580-aff4-11ea-8874-0ca683365db4

Sample repo having : JRedisTimeSeriesUserDepositTest class replicating issue above .

https://github.com/borgrodrick/JRedisTimeSeries.git

Add aggregation ALIGN option

RedisTimeSeries/RedisTimeSeries#801

Detailed TS.RANGE args with the new ALIGN feature

TS.RANGE key fromTimestamp toTimestamp [FILTER_BY_TS TS1 TS2 ..] [FILTER_BY_VALUE min max] [COUNT count] [ALIGN value] [AGGREGATION aggregationType timeBucket]
TS.REVRANGE key fromTimestamp toTimestamp [FILTER_BY_TS TS1 TS2 ..] [FILTER_BY_VALUE min max] [COUNT count] [ALIGN value] [AGGREGATION aggregationType timeBucket]

Detail of ALIGN docs

  • ALIGN - Time bucket alignment control for AGGREGATION. This will control the time bucket timestamps by changing the reference timestamp on which a bucket is defined.
    Possible values:

    • start or -: The reference timestamp will be the query start interval time (fromTimestamp).
    • end or +: The reference timestamp will be the signed remainder of query end interval time by the AGGREGATION time bucket (toTimestamp % timeBucket).
    • A specific timestamp: align the reference timestamp to a specific time.

    Note: when not provided alignment is set to 0.


Sample behaviour:

( first ingestion )

127.0.0.1:6379> ts.add serie1 1 10.0
(integer) 1
127.0.0.1:6379> ts.add serie1 3 5.0
(integer) 3
127.0.0.1:6379> ts.add serie1 11 10.0
(integer) 11
127.0.0.1:6379> ts.add serie1 21 11.0
(integer) 21

Old behaviour and the default behaviour when no ALIGN is specified ( aligned to 0 ):

127.0.0.1:6379> ts.range serie1 1 30 AGGREGATION COUNT 10
1) 1) (integer) 0
   2) 2
2) 1) (integer) 10
   2) 1
3) 1) (integer) 20
   2) 1

Align to the query start interval time (fromTimestamp)

127.0.0.1:6379> ts.range serie1 1 30 ALIGN start AGGREGATION COUNT 10
1) 1) (integer) 1
   2) 2
2) 1) (integer) 11
   2) 1
3) 1) (integer) 21
   2) 1

Align to the query end interval time (toTimestamp). The reference timestamp will be the signed remainder of query end interval time by the AGGREGATION time bucket (toTimestamp % timeBucket).

127.0.0.1:6379> ts.range serie1 1 30 ALIGN end AGGREGATION COUNT 10
1) 1) (integer) 0
   2) 2
2) 1) (integer) 10
   2) 1
3) 1) (integer) 20
   2) 1

Align to a timestamp

127.0.0.1:6379> ts.range serie1 1 30 ALIGN 1 AGGREGATION COUNT 10
1) 1) (integer) 1
   2) 2
2) 1) (integer) 11
   2) 1
3) 1) (integer) 21
   2) 1

How to select database?

Duplicated issue because of internet connection instability... Please see: #79

Hi,
I cannot select the db, how would it be possible?

Add GROUPBY and REDUCE support

Expected argument extension to TS.MRANGE: GROUPBY <label> REDUCE <reducer>

TS.MRANGE 1451679382646 1451682982646 WITHLABELS 
AGGREGATION MAX 60000 
FILTER measurement=cpu 
      fieldname=usage_user 
      hostname=(host_9,host_3,host_5,host_1,host_7,host_2,host_8,host_4)
GROUPBY hostname REDUCE MAX

Documentation extension:

  • GROUPBY - Aggregate results across different time series, grouped by the provided label name.
    For OSS clustered databases, RedisGears is required to be present.

    When combined with AGGREGATION the groupby/reduce is applied post aggregation stage.

    • label - label name to group series by.

    • reducer - Reducer type used to aggregate series that share the same label value. Available reducers: sum, min, max.

    • Note: The resulting series will contain 3 labels with the following label array structure:

      • <label>=<groupbyvalue> : containing the label name and label value.
      • __reducer__=<reducer> : containing the used reducer.
      • __source__=key1,key2,key3 : containing the source time series used to compute the grouped serie.

Example of the above features:

Query time series with metric=cpu, group them by metric_name reduce max

127.0.0.1:6379> TS.ADD ts1 1 90 labels metric cpu metric_name system
(integer) 1
127.0.0.1:6379> TS.ADD ts1 2 45
(integer) 2
127.0.0.1:6379> TS.ADD ts2 2 99 labels metric cpu metric_name user
(integer) 2
127.0.0.1:6379> TS.MRANGE - + WITHLABELS FILTER metric=cpu GROUPBY metric_name REDUCE max
1) 1) "metric_name=system"
   2) 1) 1) "metric_name"
         2) "system"
      2) 1) "__reducer__"
         2) "max"
      3) 1) "__source__"
         2) "ts1"
   3) 1) 1) (integer) 1
         2) 90
      2) 1) (integer) 2
         2) 45
2) 1) "metric_name=user"
   2) 1) 1) "metric_name"
         2) "user"
      2) 1) "__reducer__"
         2) "max"
      3) 1) "__source__"
         2) "ts2"
   3) 1) 1) (integer) 2
         2) 99

Ability to provide external redis connection

I'm using spring data redis with the Jedis client, and I would like to be able to provide a connection from that pool to RedisTimeSeries class. I couldn't find a way to do that because getConnection is currently private.

SELECTED_LABELS label1 ... support for TS.MRANGE and TS.MREVRANGE

Changes to TS.MRANGE / MREVRANGE

SELECTED_LABELS allows to request only a subset of the key-value pair labels of a serie.
An important note is that SELECTED_LABELS and WITHLABELS are mutualy exclusive.

TS.MRANGE fromTimestamp toTimestamp
          [FILTER_BY_TS TS1 TS2 ..]
          [FILTER_BY_VALUE min max]
          [COUNT count]
          [WITHLABELS | SELECTED_LABELS label1 ..]
          [AGGREGATION aggregationType timeBucket]
          FILTER filter..
          [GROUPBY <label> REDUCE <reducer>]

TS.MREVRANGE fromTimestamp toTimestamp
          [FILTER_BY_TS TS1 TS2 ..]
          [FILTER_BY_VALUE min max]
          [COUNT count]
          [WITHLABELS | SELECTED_LABELS label1 ..]
          [AGGREGATION aggregationType timeBucket]
          FILTER filter..
          [GROUPBY <label> REDUCE <reducer>]

More detailed args specs:

* WITHLABELS - Include in the reply the label-value pairs that represent metadata labels of the time series. If `WITHLABELS` or `SELECTED_LABELS` are not set, by default, an empty Array will be replied on the labels array position.
* SELECTED_LABELS - Include in the reply a subset of the label-value pairs that represent metadata labels of the time series. This is usefull when you have a large number of labels per serie but are only interested in the value of some of the labels. If `WITHLABELS` or `SELECTED_LABELS` are not set, by default, an empty Array will be replied on the labels array position.

Example:

Query time series with metric=cpu, but only reply the team label

127.0.0.1:6379> TS.ADD ts1 1 90 labels metric cpu metric_name system team NY
(integer) 1
127.0.0.1:6379> TS.ADD ts1 2 45
(integer) 2
127.0.0.1:6379> TS.ADD ts2 2 99 labels metric cpu metric_name user team SF
(integer) 2
127.0.0.1:6379> TS.MRANGE - + SELECTED_LABELS team FILTER metric=cpu
1) 1) "ts1"
   2) 1) 1) "team"
         2) "NY"
   3) 1) 1) (integer) 1
         2) 90
      2) 1) (integer) 2
         2) 45
2) 1) "ts2"
   2) 1) 1) "team"
         2) "SF"
   3) 1) 1) (integer) 2
         2) 99

Add examples and further notes about duplicate policy

Since RedisTimeSeries 1.4 we've added the ability to back-fill time series, with different duplicate policies.

However, we still see several issues being raised on the core repo/client repo that point to users no being aware of it. Example: RedisTimeSeries/redistimeseries-py#86

We should address this by adding examples and further notes about duplicate policy.
You can check our docs about duplicate policy here: https://oss.redislabs.com/redistimeseries/configuration/#duplicate_policy.

Sample Readme of python client with an example of the expected outcome of this documentation/examples task:
https://github.com/RedisTimeSeries/redistimeseries-py#further-notes-on-back-filling-time-series

Support for connection closing

Using the library, I cannot find a way to close the internal connection(s) properly (e.g. a close or shutdown method). That's quite a real issue for use in production.

Redis Pipelining Support

Hi, I would like to know if Redis Pipelining will be supported in the future. This would be great for reducing network costs 👍

Cluster mode support

Will there be cluster mode support in the future? And if so, when will it be approximately?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.