Build RPC pattern via redis connection
Project description
rpcviaredis
==========
*Using redis server to build RPC environment - by Oscar LASM*
----------
rpcviaredis intended to provide a simple tool for establishing a pattern RPC over an installation Redis.
Implement python, it is composed of:
- **Server** which serve remote commands
- **Client** Use to connect and call commands hosted on server
- **Transport protocol** Use to pack and unpack request and response during communication process
**Examples**:
Server implementation:
from rpcviaredis import *
class DummyServer(ServerRPC):
def sum(self, x, y):
return Response(response=x+y, exception=None, reason=None, return_code=200)
def naive_div(self, x, y):
return Response(response=x/y, exception=None, reason=None, return_code=200)
def multiplication(self, x, y):
return Response(response=x*y, exception=None, reason=None, return_code=200)
if __name__ == "__main__":
import redis
r = redis.StrictRedis(db=2)
s = DummyServer(r, 'test-rpc', transport_klass=JSONTransport)
try:
s.start()
except KeyboardInterrupt:
pass
finally:
s.stop()
Client Implementation
import redis
from rpcviaredis import Client
r = redis.StrictRedis(db=2)
c = Client(r, 'test-rpc', transport_klass=JsonTransport)
retval = c.sum(1,2)
print(retval.response) # print 3
==========
*Using redis server to build RPC environment - by Oscar LASM*
----------
rpcviaredis intended to provide a simple tool for establishing a pattern RPC over an installation Redis.
Implement python, it is composed of:
- **Server** which serve remote commands
- **Client** Use to connect and call commands hosted on server
- **Transport protocol** Use to pack and unpack request and response during communication process
**Examples**:
Server implementation:
from rpcviaredis import *
class DummyServer(ServerRPC):
def sum(self, x, y):
return Response(response=x+y, exception=None, reason=None, return_code=200)
def naive_div(self, x, y):
return Response(response=x/y, exception=None, reason=None, return_code=200)
def multiplication(self, x, y):
return Response(response=x*y, exception=None, reason=None, return_code=200)
if __name__ == "__main__":
import redis
r = redis.StrictRedis(db=2)
s = DummyServer(r, 'test-rpc', transport_klass=JSONTransport)
try:
s.start()
except KeyboardInterrupt:
pass
finally:
s.stop()
Client Implementation
import redis
from rpcviaredis import Client
r = redis.StrictRedis(db=2)
c = Client(r, 'test-rpc', transport_klass=JsonTransport)
retval = c.sum(1,2)
print(retval.response) # print 3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rpcviaredis-0.1.1.tar.gz
(5.3 kB
view details)
File details
Details for the file rpcviaredis-0.1.1.tar.gz.
File metadata
- Download URL: rpcviaredis-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd21f6cf58b9c43110f9554fa3f932ed5bca9ce1773c6ec9abfbf6ce45721903
|
|
| MD5 |
87cc8fa0b4619346a3faa25f39ed9052
|
|
| BLAKE2b-256 |
da23f58c71d7e35b6ff9e7811d569c4faa34b49cef349714c75fff3b47c03442
|