Lightweight RPC on Redis using Msgpack.
Project description
REdis Msgpack RPC
Installation
pip install remrpc
Example
import redis
import remrpc
def add(a, b):
return a + b
def sub(a, b):
return a - b
def multi():
return "Hello", "World"
def kvfunc(k="key", v="val"):
return "{0} = {1}".format(k, v)
def nonreturn():
print("Non Return")
class CallObject:
def __call__(self, name):
return "Hello {0}".format(name)
if __name__ == "__main__":
pool = redis.ConnectionPool(host="127.0.0.1",
port=6379,
password="123456")
rpc1 = remrpc.RPC(redis.Redis(connection_pool=pool), "channel:rpc1")
rpc2 = remrpc.RPC(redis.Redis(connection_pool=pool), "channel:rpc2")
rpc1.register(add)
rpc1.register(sub)
rpc1.register(multi)
rpc1.register(kvfunc)
rpc1.register(CallObject(), 'sayhello')
rpc1.register(nonreturn)
try:
invoker = rpc2.invoker("channel:rpc1")
print(invoker.add(1, 2))
print(invoker.sub(9, 5))
print(invoker.multi())
print(invoker.kvfunc(k="KEY", v="VALUE"))
print(invoker.sayhello("World"))
print(invoker.nonreturn())
print(invoker.nonexistent())
except remrpc.TimedoutRPC as e:
print("> RPC Timedout: {0}".format(e))
except remrpc.CallErrorRPC as e:
print("> RPC Call Error: {0}".format(e))
except remrpc.ExceptionRPC as e:
print("> RPC Exception: {0}".format(e))
rpc1.close()
rpc2.close()
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
remrpc-0.1.7.tar.gz
(4.3 kB
view hashes)
Built Distribution
remrpc-0.1.7-py3-none-any.whl
(8.6 kB
view hashes)