https://github.com/munisisazade/redis-pub-sub
Redis RPC server for microservices
https://github.com/munisisazade/redis-pub-sub
python3 redis redis-pubsub redis-rpc rpc rpc-client rpc-server
Last synced: 16 days ago
JSON representation
Redis RPC server for microservices
- Host: GitHub
- URL: https://github.com/munisisazade/redis-pub-sub
- Owner: munisisazade
- License: mit
- Created: 2019-08-30T11:24:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-11T21:25:00.000Z (over 1 year ago)
- Last Synced: 2026-03-02T02:30:25.051Z (about 1 month ago)
- Topics: python3, redis, redis-pubsub, redis-rpc, rpc, rpc-client, rpc-server
- Language: Python
- Homepage: https://pypi.org/project/redispubsub/
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redis-pub-sub
Redis RPC with PubSub simple lightweight
# Getting Started
Install Redis rpc
```bash
pip install redispubsub
```
### Server example
```python
import os
from redisrpc import RedisRPC
# Add REDIS_URI application enviroment variable
os.environ.setdefault("REDIS_URI", "redis://localhost:6379/0")
rpc = RedisRPC("channel_name") # rename what you want
# event lists
def calc_square(response): # `response` is a sender data
power_of_number = response**2
return power_of_number # sent to client
def calc_cube(response): # `response` is a sender data
cube_of_number = response**3
return cube_of_number # sent to client
rpc.register(calc_square, "square") # event name default function name
rpc.register(calc_cube, "cube")
rpc.listen()
```
### Client interface
```python
import os
from redisrpc import RedisRPC
# Add REDIS_URI application enviroment
os.environ.setdefault("REDIS_URI", "redis://localhost:6379/0")
rpc = RedisRPC("channel_name") # channel name must be same as server
square = rpc.send("square", 5) # send data to spesific event
cube = rpc.send("cube", 3)
# response from server handlers
print(square) # 25
print(cube) # 27
```
# Contributing
Fell free to open issue and send pull request.