# Redis Tasks


This module contains a collection of tasks for interacting with Redis via the redis-py library.

# RedisSet

class

prefect.tasks.redis.redis_tasks.RedisSet

(host="localhost", port=6379, db=0, password_secret="REDIS_PASSWORD", redis_key=None, redis_val=None, redis_connection_params=None, ex=None, px=None, nx=False, xx=False, **kwargs)[source]

Task for setting a Redis key-value pair.

Args:

  • host (str, optional): name of Redis host, defaults to 'localhost'
  • port (int, optional): Redis port, defaults to 6379
  • db (int, optional): redis database index, defaults to 0
  • password_secret (str, optional): the name of the Prefect Secret that stores your Redis credentials
  • redis_key (str, optional): Redis key to be set, can be provided at initialization or runtime
  • redis_val (Redis native type, optional): Redis val to be set, can be provided at initialization or runtime, Redis native types include strings, dictionaries, lists, sets, and sorted sets
  • redis_connection_params (dict, optional): key-value pairs passed to the redis.Redis connection initializer
  • ex (int, optional): if provided, sets an expire flag, in seconds, on 'redis_key' set
  • px (int, optional): if provided, sets an expire flag, in milliseconds, on 'redis_key' set
  • nx (int, optional): if set to True, set the value at 'redis_key' to 'redis_val' only if it does not exist, defaults to False
  • xx (int, optional): if set to True, set the value at 'redis_key' to 'redis_val' only if it already exists, defaults to False
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.redis.redis_tasks.RedisSet.run

(redis_key=None, redis_val=None, ex=None, px=None, nx=False, xx=False)[source]

Task run method. Sets Redis key-value pair.

Args:

  • redis_key (str, optional): Redis key to be set, can be provided at initialization or runtime
  • redis_val (Redis native type, optional): Redis val to be set, can be provided at initialization or runtime, Redis native types include strings, dictionaries, lists, sets, and sorted sets
  • ex (int, optional): if provided, sets an expire flag, in seconds, on 'redis_key' set
  • px (int, optional): if provided, sets an expire flag, in milliseconds, on 'redis_key' set
  • nx (int, optional): if set to True, set the value at 'redis_key' to 'redis_val' only if it does not exist, defaults to False
  • xx (int, optional): if set to True, set the value at 'redis_key' to 'redis_val' only if it already exists, defaults to False
Returns:
  • bool: status of set operation
Raises:
  • ValueError: if redis_key or redis_val is not provided



# RedisGet

class

prefect.tasks.redis.redis_tasks.RedisGet

(host="localhost", port=6379, db=0, password_secret="REDIS_PASSWORD", redis_connection_params=None, redis_key=None, **kwargs)[source]

Task for getting a value based on key from a Redis connection.

Args:

  • host (str, optional): name of Redis host, defaults to 'localhost'
  • port (int, optional): Redis port, defaults to 6379
  • db (int, optional): redis database index, defaults to 0
  • password_secret (str, optional): the name of the Prefect Secret that stores your Redis password
  • redis_connection_params (dict, optional): key-value pairs passed to the redis.Redis connection initializer
  • redis_key (str, optional): Redis key to get value, can be provided at initialization or runtime
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.redis.redis_tasks.RedisGet.run

(redis_key=None)[source]

Task run method.

Args:

  • redis_key (str, optional): Redis key to get value, can be provided at initialization or runtime
Returns:
  • value: value associated with redis_key
Raises:
  • ValueError: if redis_key is not provided



# RedisExecute

class

prefect.tasks.redis.redis_tasks.RedisExecute

(host="localhost", port=6379, db=0, password_secret="REDIS_PASSWORD", redis_connection_params=None, redis_cmd=None, **kwargs)[source]

Task for executing a command against a Redis connection

Args:

  • host (str, optional): name of Redis host, defaults to 'localhost'
  • port (int, optional): Redis port, defaults to 6379
  • db (int, optional): redis database index, defaults to 0
  • password_secret (str, optional): the name of the Prefect Secret that stores your Redis credentials
  • redis_connection_params (dict, optional): key-value pairs passed to the redis.Redis connection initializer
  • redis_cmd (str, optional): Redis command to execute, must be provided at initialization or runtime
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.redis.redis_tasks.RedisExecute.run

(redis_cmd=None)[source]

Task run method. Executes a command against a Redis connection.

Args:

  • redis_cmd (str, optional): Redis command to execute, must be provided at initialization or runtime
Returns:
  • result: result of executed Redis command



This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC