nfarring / redisrpc Goto Github PK
View Code? Open in Web Editor NEWLightweight RPC using Redis
License: GNU General Public License v3.0
Lightweight RPC using Redis
License: GNU General Public License v3.0
do you plan subject?
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?
How about the situaion about client rpc call timeout? Does the server still rpush the response_queue, and client never consumes the message ?
$ 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
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:
__init__
functioncall
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)
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)
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.