Skip to main content

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)

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')

    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.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


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.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remrpc-0.1.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file remrpc-0.1.2.tar.gz.

File metadata

  • Download URL: remrpc-0.1.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for remrpc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9b107a20e95b99a510c64e4b769d92cc258daa6d04157433e6dc7af393309d28
MD5 e229c7d4cb12086ede0f3a52d9b0598f
BLAKE2b-256 462d8149b06a181799e8b6eb71a1869d9099573d349a01adcdccc403244b01df

See more details on using hashes here.

File details

Details for the file remrpc-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: remrpc-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for remrpc-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c8bc93a4834b3698b2acd941a9041db4d56ce829108c3631fb65bb19f937c9c
MD5 22e313d0a68e24e5015c5dd195402de1
BLAKE2b-256 364b636c8a3cf1e29df694e34ae2d423af6da32f9475f068033e329326e33bd0

See more details on using hashes here.

Supported by

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