Skip to main content

Library to exchange messages between workers using Redis Streams

Project description

Redis Message API Overview This Python module provides an interface to interact with a Redis server for sending, receiving, and processing messages and files. The RedisMsgAPI class facilitates the use of Redis streams to create and manage message groups, send and receive messages, and handle files across different streams.

Features Message Processing: Convert Redis stream messages to JSON format. Message Acknowledgment: Acknowledge messages in the stream after processing. File Handling: Send single or multiple file names as messages through Redis streams. Customizable: Allows for custom Redis host configuration through environment variables or default settings. Installation Make sure you have Redis and Python installed. You can install the required Python packages using pip:

bash Copy code pip install redis Usage Initialization To use the RedisMsgAPI, you need to create an instance of the class with the required parameters:

python Copy code from redis_msg_api import RedisMsgAPI

api = RedisMsgAPI( group_name="your_group_name", in_stream_key="input_stream", in_app="app_name", out_stream_key="output_stream", out_file_key="output_file_stream", out_files_keys="output_files_stream", out_app="out_app_name", worker_name="worker_name" ) Methods process_message(message): Processes a message from the Redis stream and returns it as a JSON string.

get_message(in_stream): Retrieves a message from the specified input stream.

get_message_data(message_id): Retrieves message data based on the message ID.

ack_message(message_id): Acknowledges a message in the stream.

send_message(json_message): Sends a message to the output stream in JSON format.

send_message_data(message_data): Sends message data to the output stream.

send_file(file_name): Sends a file name as a message to the output file stream.

send_multiple_files(file_list): Sends multiple file names as a single message to the output files stream.

Example Here is an example of how to use the RedisMsgAPI class:

python Copy code api = RedisMsgAPI( group_name="example_group", in_stream_key="in_stream", in_app="example_app", out_stream_key="out_stream", out_file_key="out_file", out_files_keys="out_files", out_app="out_app", worker_name="worker_1" )

Sending a message

api.send_message_data({"key": "value"})

Receiving and processing a message

message = api.get_message("in_stream") print("Received Message:", message)

Acknowledging a message

api.ack_message("message_id") Configuration You can configure the Redis host using an environment variable. By default, the class connects to a Redis server on localhost on port 6379.

To change the Redis host, set the REDIS_HOST environment variable:

bash Copy code export REDIS_HOST="your_redis_host" License This project is licensed under the MIT License - see the LICENSE file for details.

To create the library use the following command codes rm -rf dist/ build/ python3 setup.py sdist bdist_wheel twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis_worker_API-0.5.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_worker_API-0.5.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file redis_worker_API-0.5.4.tar.gz.

File metadata

  • Download URL: redis_worker_API-0.5.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for redis_worker_API-0.5.4.tar.gz
Algorithm Hash digest
SHA256 1b43c3535cee475f881ea7a393dafb9841d25cb22dcf64a4f8bdc2f0a88600a9
MD5 06e16c980920a012661ddde4c599d2f8
BLAKE2b-256 1885b984b2b1a0ea61465b3099aecd1c8f36f2d7111997f205ddaea91d88578d

See more details on using hashes here.

File details

Details for the file redis_worker_API-0.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_worker_API-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5a5f33a23fc043069185481628219c95aa4beeb86398294ab50d67d0f7b2fdb0
MD5 47541636e6da8f3573ef5fb5a180331b
BLAKE2b-256 6ac8bb39005141ba7d018a0f303bd70415db50228a3255d33e641af9758e91a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page