Skip to main content

Simple HTTP client which takes request data from redis

Project description

redis2http

Redis2http takes request data from redis and performs HTTP request. Mostly used to implement web-hook calls

Why not requests.get/requests.post ?

Most likely you want main program to run fast and spend very short time on calling hook. HTTP requests are not good for it - it may fail or be slow for many reasons. On other hand, LPUSH operation with local redis is always very quick and very reliable.

redis2http is good if a) You do not need to wait for HTTP request completion b) You do not need to get any reply from request

Install

pip3 install redis2http

If you want to start on boot (as root or sudo):

cp /usr/local/redis2http/redis2http.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable redis2http
systemctl start redis2http

Usage for CLI

CLI is not main purpose for redis2http, but it's good for testing. Examples:

To start as service in foreground (for debugging), just run redis2http.py (not options required).

To send request via redis (for debugging):

redis2http.py --send GET https://google.com/

After this (in less then second), you can see result in redis2http service output. If redis2http runs as systemd service, then sudo journalctl -u redis2http.

Usage from Python or from whatever (via redis)

Put JSON-encoded data structure to http_requests_queue list (or use -q for other key name). Python example:

data = {
    'method': 'GET',
    'url': 'https://example.com/hook',
    'payload': None
}
request = json.dumps(data)
redis_connection.sadd('http_requests_queue', request)

Set vs List

redis2http may use queue as redis object of type set or type list. You may specify type as --type CLI option. Default is set.

If you will use set and submit same data twice, only one HTTP request will be performed. If you will use list, both requests will be performed.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

redis2http-0.0.2-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

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