Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install redisrpc

How to install redisrpc

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install redisrpc
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.3.4 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.2.1 Available View build log
0.1.2 Available View build log
Windows (64-bit)
0.3.4 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.2.1 Available View build log
0.1.2 Available View build log
Mac OS X (10.5+)
0.3.4 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.2.1 Available View build log
0.1.2 Available View build log
Linux (32-bit)
0.3.4 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.2.1 Available View build log
0.1.2 Available View build log
Linux (64-bit)
0.3.4 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.2.1 Available View build log
0.1.2 Available View build log
 
Dependencies
Imports
Lastest release
version 0.3.4 on May 24th, 2012

by Nathan Farrington http://nathanfarrington.com

RedisRPC is the easiest to use RPC library in the world. (No small claim!) It has implementations in Ruby, PHP, and Python.

Introduction

Redis is a powerful in-memory data structure server that is useful for building fast distributed systems. Redis implements message queue functionality with its use of list data structures and the LPOP, BLPOP, and RPUSH commands. RedisRPC implements a lightweight RPC mechanism using Redis message queues to temporarily hold RPC request and response messages. These messages are encoded as JSON strings for portability.

Many other RPC mechanisms are either programming language specific (e.g. Java RMI) or require boiler-plate code for explicit typing (e.g. Thrift). RedisRPC was designed to be extremely easy to use by eliminating boiler-plate code while also being programming language neutral. High performance was not an initial goal of RedisRPC and other RPC libraries are likely to have better performance. Instead, RedisRPC has better programmer performance; it lets you get something working immediately.

Calculator Example

Each library implementation uses the same client and server example based off of a mutable calculator object. The clients and servers from different languages are interoperable.

http://github.com/nfarring/redisrpc/raw/master/docs/redisrpc_example.png

System Message: WARNING/2 (<string>, line 40)

Explicit markup ends without a blank line; unexpected unindent.
align:center
alt:

#. The client issues an RPC Request by using the Redis RPUSH command to push an RPC Request message into a Redis list called calc. #. The server retrieves the RPC Request message by using the Redis BLPOP command. #. The server dispatches the RPC Request to a local object, which in this case is a Calculator object. #. The server accepts the return value (or exception) from the Calculator object. #. The server issues an RPC Response by using the Redis RPUSH command to push an RPC Response message into a Redis list called calc:rpc:<RAND_STRING>, which was chosen by the client. #. The client retrieves the RPC Response message by using the Redis BLPOP command.

Note that the server or client can be made non-blocking by using the Redis LPOP command instead of BLPOP. I currently do not need this feature and have not added support for this, but patches are welcome.

That's all there is to it!

Ruby Usage

client.rb

System Message: WARNING/2 (<string>, line 71)

Literal block expected; none found.

redis_server = Redis.new message_queue = 'calc' calculator = RedisRPC::Client.new redis_server, 'calc' calculator.clr calculator.add 5 calculator.sub 3 calculator.mul 4 calculator.div 2 assert calculator.val == 4

server.rb

System Message: WARNING/2 (<string>, line 86)

Literal block expected; none found.

redis_server = Redis.new message_queue = 'calc' local_object = Calculator.new server = RedisRPC::Server.new redis_server, message_queue, local_object server.run

PHP Usage

Note that the PHP library does not currently support named function arguments.

client.php
$redis_server = new Predis\Client();
$message_queue = 'calc';
$calculator = new RedisRPC\Client($redis_server, $message_queue);
$calculator->clr();
$calculator->add(5);
$calculator->sub(3);
$calculator->mul(4);
$calculator->div(2);

System Message: ERROR/3 (<string>, line 111)

Inconsistent literal block quoting.

assert($calculator->val() == 4);

server.php
$redis_server = new Predis\Client();
$message_queue = 'calc';
$local_object = new Calculator();
$server = new RedisRPC\Server($redis_server, $message_queue, $local_object);
$server->run();

Python Usage

client.py

System Message: WARNING/2 (<string>, line 132)

Literal block expected; none found.

redis_server = redis.Redis() message_queue = 'calc' calculator = redisrpc.Client(redis_server, message_queue) calculator.clr() calculator.add(5) calculator.sub(3) calculator.mul(4) calcaultor.div(2) assert calculator.val() == 4

server.py

System Message: WARNING/2 (<string>, line 147)

Literal block expected; none found.

redis_server = redis.Redis() message_queue = 'calc' local_object = calc.Calculator() server = redisrpc.Server(redis_server, message_queue, local_object) server.run()

Installation

Ruby Installation

The redis-rb library is required. Install using RubyGems:

System Message: WARNING/2 (<string>, line 164)

Literal block expected; none found.

gem install redisrpc

PHP Installation

The Predis library is required.

The RedisRPC PHP library is available from Packagist at: http://packagist.org/packages/nfarring/redisrpc. You can use Composer to install into your PHP project.

Python Installation

The redis-py library is required.

The RedisRPC Python library is available from PyPI at: http://pypi.python.org/pypi/redisrpc. You can install with pip.

System Message: WARNING/2 (<string>, line 190)

Literal block expected; none found.

pip install redisrpc

Internal Message Formats

All RPC messages are JSON objects. User code will never see these objects because they are handled by the RedisRPC library.

RPC Request

An RPC Request contains two members: a function_call object and a response_queue string.

A function_call object has one required member: a name string for the function name. It also has two optional members: (a) an args list for positional function arguments, and (b) a kwargs object for named function arguments.

The response_queue string is the name of the Redis list where the corresponding RPC Response message should be pushed by the server. This queue is chosen programmatically by the client to be collision free in the Redis namespace. Also, this queue is used only for a single RPC Response message and is not reused for future RPC Response messages.

{ "function_call" : {

System Message: ERROR/3 (<string>, line 218)

Inconsistent literal block quoting.

"args" : [ 1, 2, 3 ], "kwargs" : { "a" : 4, "b" : 5, "c" : 6 }, "name" : "foo" }, "response_queue" : "calc:rpc:X7Y2US" }

RPC Response (Successful)

If an RPC is successful, then the RPC Response object will contain a single member, a return_value of some JSON type.

{ "return_value" : 4.0 }
RPC Response (Exception)

If an RPC encounters an exceptional condition, then the RPC Response object will contain a single member, an exception string. Note that the value of the exception string might not have any meaning to the client since the client and server might be written in different languages or the client might have no knowledge of the server's wrapped object. Therefore the best course of action is probably to display the exception value to the user.

{ "exception" : "AttributeError(\\"\'Calculator\' object has no attribute \'foo\'\\",)" }

Source Code

Source code is available at http://github.com/nfarring/redisrpc.

License

This software is available under the GPLv3 or later.

Changelog

Version 0.3.4

  • Client now supports optional timeout.
  • Server now deletes message queue when starting.
  • PHP: Fixed exception handling.

Version 0.3.3

  • Ruby: Added a Ruby library implementation.

Version 0.3.2

  • Fixed some formatting in README.markdown that was causing problems

System Message: WARNING/2 (<string>, line 278)

Bullet list ends without a blank line; unexpected unindent.

when converted to reStructredText. - Added version information to README.markdown. - Added installation instructions to README.markdown. - Python: Added RPC message logging using the logging module. - Python: Added redis as an installation dependency. - Python: Now using Distribute instead of distutils.

Version 0.3.1

  • PHP: Changed composer.json predis dependency version.

Version 0.3.0

  • Empty function call args and kwargs are no longer transmitted.
  • PHP: Added support for the PHP language.
  • PHP: Now installable with PHP Composer.
  • Python: Shortened the Client and Server class names.
  • Python: Debugging modified to print JSON representation.
  • Python: Switched the README file back to ReStructred Text.

Version 0.2.1

  • Python: Fixed MANIFEST.in to reflect filename changes.

Version 0.2.0

  • Simplified the JSON RPC message format.
  • Documented the JSON RPC message format.
  • Python: Using HTML file for README, will it work?
  • Python: Renamed calc_client to client.py.
  • Python: Renamed calc_server to server.py.
  • Python: Added a RemoteException class, which can be raised by the

System Message: WARNING/2 (<string>, line 310)

Bullet list ends without a blank line; unexpected unindent.

client.

Version 0.1.2

  • Python: Fixed the download_url in setup.py.
  • Python: Renamed the README file to README.rst to support browsing on

System Message: WARNING/2 (<string>, line 316)

Bullet list ends without a blank line; unexpected unindent.

Github.

Version 0.1.1

  • Python: Added README.
  • Python: Added long_description to setup.py.
  • Python: Added MANIFEST.in file.
  • Python: Added examples/ subdirectory to MANIFEST.
  • Python: Modified examples/ directory to be consistent with README

System Message: WARNING/2 (<string>, line 325)

Bullet list ends without a blank line; unexpected unindent.

file. - Python: Fixed the download_url in setup.py.

Version 0.1.0

  • Changed to the GPL license.
  • Python: Removed unused functionality from python/redisrpc.py.
  • Python: Added a setup.py installer script.

Subscribe to package updates

Last updated May 24th, 2012

Download Stats

Last month:7

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.