GithubHelp home page GithubHelp logo

redisrpc's People

Contributors

nfarring avatar yaauie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redisrpc's Issues

Python install failure

When I try to install for Python, I get the following error:

Traceback (most recent call last):
  File "setup.py", line 26, in <module>
    with open('README.rst','r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'README.rst'

Looks like it can't find the README file. Did this get converted to markdown at some point or is this a different file?

pip install redisrpc doesn't work

$ pip install redisrpc
Downloading/unpacking redisrpc
  Could not find any downloads that satisfy the requirement redisrpc
  Some externally hosted files were ignored (use --allow-external redisrpc to allow).
Cleaning up...
No distributions at all found for redisrpc
Storing debug log for failure in /home/iman/.pip/pip.log

Issue when complex objects are passed as argument

In the Python version, when called using complex Python object with __str__ method the rpc fails as the object converted to its string representation.

The fix is relatively simple:

  1. Modify the FunctionCall object:
    1.1. Change the __init__ function
    1.2. Created a function call call that first get the function attrbute name of the object and then pass the args and kwargs
class FunctionCall(dict):
    """Encapsulates a function call as a Python dictionary."""

    @staticmethod
    def from_dict(dictionary):
        """Return a new FunctionCall from a Python dictionary."""
        name = dictionary.get('name')
        args = dictionary.get('args')
        kwargs = dictionary.get('kwargs')
        return FunctionCall(name, args, kwargs)

    def __init__(self, name, args=None, kwargs=None):
        """Create a new FunctionCall from a method name, an optional argument tuple, and an optional keyword argument
        dictionary."""
        self['name'] = name
        if not args:
            self['args'] = []
        else:
            self['args'] = args
        if not kwargs:
            self['kwargs'] = [{}]
        else:
            self['kwargs'] = kwargs

    def call(self, local_object):
        func = getattr(local_object, self['name'])
        return func(*self['args'], **self['kwargs'])

    def as_python_code(self):
        """Return a string representation of this object that can be evaled to execute the function call."""
        argstring = '' if 'args' not in self else \
                ','.join(str(arg) for arg in self['args'])
        kwargstring = '' if 'kwargs' not in self else \
                ','.join('%s=%s' % (key,val) for (key,val) in list(self['kwargs'].items()))
        if len(argstring) == 0:
            params = kwargstring
        elif len(kwargstring) == 0:
            params = argstring
        else:
            params = ','.join([argstring,kwargstring])
        return '%s(%s)' % (self['name'], params)
  1. The Server class also needs to be modified to replace the exec statement with function_call.call(self.local_object)
class Server(object):
    """Executes function calls received from a Redis queue."""

    def __init__(self, redis_server, message_queue, local_object):
        self.redis_server = redis_server
        self.message_queue = message_queue
        self.local_object = local_object
 
    def run(self):
        # Flush the message queue.
        self.redis_server.delete(self.message_queue)
        while True:
            message_queue, message = self.redis_server.blpop(self.message_queue)
            message_queue = message_queue.decode()
            assert message_queue == self.message_queue
            logging.debug('RPC Request: %s' % message)
            transport, rpc_request = decode_message(message)
            response_queue = rpc_request['response_queue']
            function_call = FunctionCall.from_dict(rpc_request['function_call'])
            self.value = function_call.call(self.local_object)
            rpc_response = dict(return_value=self.value)
            message = transport.dumps(rpc_response)
            logging.debug('RPC Response: %s' % message)
            self.redis_server.rpush(response_queue, message)

string arguments

Current code has a problem with sending string arguments.

I have added this method to examples/calc.py

def hello(self, name):
    print name
    return 'hello %s' % name

and then I try to call it from client:

assert calculator.hello('ali') == 'hello ali'

But it raises this exception:
redisrpc.RemoteException: NameError("name 'ali' is not defined",)

The problem is in FunctionCall.as_python_code. It strips the quotes (' or ") of strings. If we send string value of "10 - 2", it will get it int value 8.

Add support for Python Twisted (txRedis)

The current Python support uses blocking I/O.
It would be great if an option existed to use txRedis, which is the non-blocking I/O Python Twisted implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.