Send and receive messages via a Redis server
Project description
RedisBridge
RedisBridge is a Python package that handles sending and receiving messages across clients via a Redis server.
Installation
pip install RedisBridge
Server
This package does NOT actually require running a Redis server. As long as you are only running one RedisBridge instance on a single process, the bridge is able to simulate a server by storing state internally (see docs).
However, for high-performance applications, one may want to spin up an actual Redis server. See Redis's quickstart for installation instructions.
Docs
For much more detail about RedisBridge classes, messages, and usage patterns, check out the documentation. Seriously, go take a look.
Basic Usage
- Spin up a Redis server
$ redis-server --port 6379
- Create a bridge on each client
>>> from RedisBridge import RedisBridge
>>> bridge = RedisBridge(host='localhost', port=6379)
- Register clients to receive messages on a given channel through a
CallbackInterface
>>> def callback(msg):
... print('Received message:', msg)
>>> from RedisBridge.interfaces import CallbackInterface
>>> CallbackInterface(bridge).register_callback(callback, channel='my_channel')
- Start each bridge to begin sending/receiving messages
>>> bridge.start()
- Send messages to other clients via bridge
>>> bridge.send('Hello World!', channel='my_channel')
CallbackInterface
calls all callbacks registered with it on the given channel
Received message: <Message: id='t2yedxi3', channel='my_channel', data='Hello World!'>
- Stop a bridge to close its connection to the server
>>> bridge.stop()
Demos
For some toy examples and demos, check out the demos folder.
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
Built Distribution
Hashes for RedisBridge-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b051414b60d834d8b0ba302f20f984fe22e9f7dceb5ac7089955385b3121f7d |
|
MD5 | 8c002125878adea86f84a48fa30810d6 |
|
BLAKE2b-256 | be82deb187c36ecf8c951df9e738975aa72aa150cd994b267db0ad9c1a81dacd |