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)

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


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.11.tar.gz (4.4 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.11-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: remrpc-0.1.11.tar.gz
  • Upload date:
  • Size: 4.4 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.11.tar.gz
Algorithm Hash digest
SHA256 f5bfe2af1702090ef34ce8a517eea3f9876ff7ba50f5a8f65e101d453f8b671e
MD5 150629e2c473e2b88de5405de62c0b6c
BLAKE2b-256 cefcc476b4ddc674fcb5b36195bdd12ffc208be85bc1f8477047ba54f442813f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: remrpc-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 8.7 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 6cfcde76379f3098c0c14713ee0b7a528b6a9f7a5abe78316b348814b318f303
MD5 14077e36f41cd96de4929487deab0d6d
BLAKE2b-256 009afa766f3d93ef60bb568e2c566c417d751d00dd8635ec0cc3d6001141a3b4

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