Table of contents
1.
Introduction
2.
Creating a TimeSeries
3.
Features
4.
Client libraries
5.
Using other tools metrics tools
5.1.
Prometheus
5.2.
Grafana
5.3.
Configuration
5.4.
Telegraph
5.5.
Build From Source
6.
Memory model
7.
Frequently Asked Questions
7.1.
Is Redis a timeseries database?
7.2.
What is the Redis time series?
7.3.
Is Redis good for real-time?
8.
Conclusion
Last Updated: Mar 27, 2024

Time series with Redis stack

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Redis Time Series is a Redis module that adds a time series data structure to Redis. A time series is a collection of memory bits connected together. Each chunk has a predetermined sample size. Each sample is a 128-bit tuple, with the timestamp and value separated by 64 bits.

Creating a TimeSeries

The TS.Construct command can be used to create a new TimeSeries; for example, run the following: TS to make a timeseries named sense, run the following:

TS.CREATE sense


With the RETENTION option, you can prohibit your timeseries from increasing forever by defining a sample age restriction compared to the last event time. The default retention value is 0, which indicates that the series will not be trimmed.

TS.CREATE sense RETENTION 2678400000


This will create a timeseries called sense and trim it to values of up to one month.

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
     
  • Downsampling/compaction for automatically updated aggregate timeseries
     
  • Secondary indexing for time series entries. Each time series has labels (field value pairs) which will allow querying by labels.

Client libraries

RedisTimeSeries contains a number of client libraries that abstract the API in several programming languages and were built by the module authors and community members.

While using the raw Redis commands API is possible and straightforward, it is usually more convenient to use a client library that abstracts it.

Using 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 7.1+ - using the Redis Data Source.
     
  3. Telegraph
     
  4. StatsD, Graphite exports using graphite protocol.

Prometheus

Redis TimeSeries Adapter gets Prometheus metrics through remote write and uses the TimeSeries module to write them to Redis.

To build the project:

make build
cd bin


To send metrics to Redis, provide the address in host:port format.

redis-ts-adapter --redis-address localhost:6379


To receive metrics from Prometheus, Add remote write section to prometheus configuration:

remote_write:
  - url: 'http://127.0.0.1:9201/write'


Makefile commands

run tests:

make test


go linting:

make lint


Redis Sentinel

Use the redis-sentinel flag if you're using Redis Sentinel for high availability redis:

redis-ts-adapter --redis-sentinel-address localhost:26379 --redis-sentinel-master mydb

Grafana

Grafana's Redis Data Source is a plugin that allows users to connect to any Redis database, both on-premises and in the cloud. It includes pre-built dashboards and allows you to create custom dashboards to monitor Redis and application data.

Redis Data Source can be downloaded through the Grafana Marketplace or installed using the grafana-cli command line tool:

grafana-cli plugins install redis-datasource

Source

For Docker instructions and installation without Internet access, follow the Quickstart page.

Configuration

Data Source allows connection to Redis using TCP port, Unix socket, Cluster, Sentinel and supports SSL/TLS authentication.

Source

Telegraph

Telegraph is a collection, processing, aggregation, and writing agent for metrics. Based on a plugin framework that allows community developers to simply add support for new metric collecting. There are four distinct types of plugins:

  1. Input Plugins gather data from the system, services, and third-party APIs.
     
  2. Processor Plugins decorate, transform, and filter metrics
     
  3. Aggregator Plugins generate total metrics (e.g., min, max, mean, quantiles, etc.)
     
  4. Output Plugins write metrics to various destinations

Build From Source

Telegraph requires the Go version 1.18 or newer, and the Makefile requires GNU make.

  1. Install Go >=1.18 (1.18.0 recommended)
     
  2. Clone the Telegraf repository:
    git clone https://github.com/influxdata/telegraf.git
     
  3. Run make from the source directory
    cd telegraph

make

Memory model

A time series is a linked list of memory chunks. Each chunk has a predefined size of samples. Each sample is a 128-bit tuple: 64 bits for the timestamp and 64 bits for the value.

Frequently Asked Questions

Is Redis a timeseries database?

The RedisTimeSeries module makes using Redis for time-series applications like IoT data, market prices, and telemetry much easier. You may consume and query millions of samples and events at the speed of Redis with RedisTimeSeries.
 

What is the Redis time series?

A time series is a collection of memory bits connected together. Each chunk has a predetermined sample size. Each sample is a 128-bit tuple, consisting of 64 bits for the timestamp and 64 bits for the value.
 

Is Redis good for real-time?

With streaming technologies, Redis can be used as an in-memory data storage system like Apache Kafka and Amazon Kinesis to ingest, process, and analyze real-time data with sub-millisecond latency. For real-time analytics use cases, including social media analytics, ad targeting, personalization, and IoT, Redis is an excellent solution.

Conclusion

In this article, we have extensively discussed the way of adding Time Series API with Redis stack.

We hope that this blog has helped you enhance your knowledge regarding Time Series API with Redis stack. 

After reading about theTime series with Redis stack, are you not feeling excited to read/explore more articles on the topic of Unity? Don't worry; Coding Ninjas has you covered. To learn, see Operating SystemUnix File SystemFile System Routing, and File Input/Output.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass