I’ve been working on a very simple project that allow processes or computers to communicate seamlessly using Redis as a backend. I love Redis because it’s very powerful, yet very simple to configure and use. Let’s first understand the motivation behind redique
The motivation is the need for a small, cool, json-based, super-fast RPC system between processes, that led me to build a tiny project on top of Redis database and I called it Redique
Redique is an implementation of a high-performance Async RPC/Task Queue system built on top of Redis datastructure store and JSON marshalling protocol.
You normally want to use redique when you need to publish tasks to a set of workers to process asynchronously and retrieve the result using a task_id, or when you want to distribute workload over multiple workers easily without going through the hassle of understanding how message buses work.
Getting Started
You need to install the package first using pip:
# pip install redique
Then you need to create a backend class that contains the actual logic you want implement over the transport
class Calculator(object):
def add(self, x, y):
return x + y
def raiseError(self):
raise Exception("An Error Happened!")
Then you need to create a queue consumer on your worker side:
import redique
calculator = Calculator()
queue = redique.RediQue("calculator")
queue.consume_loop(calculator)
The last statement will block forever consuming tasks as they arrive.
On the publisher machine you need to execute tasks remotely
import redique
queue = redique.RediQue("calculator")
task_id = queue.push_task("add", 1, 2)
print queue.get_task_state(task_id)
print queue.wait_task_result(task_id)
Another way to do that is to call execute_task that blocks till the result is returned
import redique
queue = redique.RediQue("calculator")
print queue.execute_task("add", 1, 2)
You can grab the source code from https://github.com/AhmedSoliman/redique










by Anas Ibrahim
04 Oct 2011 at 10:33
Thanks for the very informative post
by Abdalla Mahmoud
04 Oct 2011 at 10:43
So great and simple, viva lightweight frameworks I hate heavy platforms with dozens of configuration tasks !
by Mohammad Aboali
04 Oct 2011 at 11:56
Very interesting, I wonder how far can we implement this on low process levels, to achieve load balancing between networked DB servers instead of going to high level protocol limited c-jdbc sophisticated for example.
by Ahmed S. Farghal
04 Oct 2011 at 12:58
I don’t really think this is proper for DB load-balancing, but it’s definitely suitable for background processing of long tasks
by Ahmed El Refaey
16 Oct 2011 at 03:15
Thanks Ahmed for that nice work.
I’m interested to know more elaborate explanation of the rule of Redis in this solution, and how would be the configuration to run the consumers on remote processes.
Thanks,