Redis Provider for Apache Airflow

4.4.3 · active · verified Sun Apr 12

This is a provider package for Apache Airflow that enables seamless interaction with Redis. It offers hooks, operators, and sensors to integrate various Redis operations, such as setting/getting keys, publishing/subscribing to channels, and monitoring key events, directly into Airflow DAGs. The current version is 4.4.3, and Apache Airflow providers typically maintain an active release cadence, often aligning with Airflow core updates or independent feature/bug fixes.

Warnings

Install

Imports

Quickstart

This DAG demonstrates how to use the `RedisOperator` to perform basic Redis commands like `SET`, `GET`, and `INCR`. It assumes you have an Airflow connection named `redis_default` configured in your Airflow UI or `airflow.cfg` that points to your Redis instance (e.g., Host: `localhost`, Port: `6379`, Connection Type: `Redis`).

from __future__ import annotations

import pendulum

from airflow.models.dag import DAG
from airflow.providers.redis.operators.redis import RedisOperator

with DAG(
    dag_id="redis_example_dag",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=["redis", "example"],
) as dag:
    # Set a key-value pair in Redis using the default connection (redis_default)
    set_value_task = RedisOperator(
        task_id="set_my_key",
        command="SET my_key 'Hello from Airflow!'",
        redis_conn_id="redis_default",
    )

    # Get the value of a key from Redis
    get_value_task = RedisOperator(
        task_id="get_my_key",
        command="GET my_key",
        redis_conn_id="redis_default",
    )
    
    # Increment a counter
    increment_task = RedisOperator(
        task_id="increment_counter",
        command="INCR counter",
        redis_conn_id="redis_default",
    )

    set_value_task >> get_value_task >> increment_task

view raw JSON →