# HG changeset patch # User mcroydon # Date 1242129108 0 # Node ID 586c2984188ba87f9f428ddca74fd7c1fa34f8a2 # Parent 383b7c497164e6cd6b19a49dab54b7218d0e62eb Added first run at redisd backend using the MIT-licensed redis client included in the redis source. This backend does not yet support supplying host, port, and db (need to rethink configuration a bit). diff -r 383b7c497164 -r 586c2984188b queues/backends/redisd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/queues/backends/redisd.py Tue May 12 11:51:48 2009 +0000 @@ -0,0 +1,66 @@ +""" +Backend for redis. + +Requires redis.py from the redis source (found in client-libraries/python). +""" + +from queues.backends.base import BaseQueue +from queues import InvalidBackend, QueueException + +try: + import redis +except ImportError: + raise InvalidBackend("Unable to import redis.") + +# TODO: Import host, port, db + +class Queue(BaseQueue): + def __init__(self, name): + try: + self.name = name + self.backend = 'redis' + self._connection = redis.Redis() + except redis.RedisError, e: + raise QueueException, "%s" % e + + def read(self): + try: + return self._connection.pop(self.name) + except redis.RedisError, e: + raise QueueException, "%s" % e + + def write(self, value): + try: + resp = self._connection.push(self.name, value) + if resp == 'OK': + return True + else: + return False + except redis.RedisError, e: + raise QueueException, "%s" % e + + def __len__(self): + try: + return self._connection.llen(self.name) + except redis.RedisError, e: + raise QueueException, "%s" % e + + def __repr__(self): + return "" % self.name + +def create_queue(): + """This isn't required, so we noop. Kept here for swapability.""" + return True + +def delete_queue(name): + try: + resp = redis.Redis().delete(name) + if resp: + return True + else: + return False + except redis.RedisError, e: + raise QueueException, "%s" % e + +def get_list(): + return redis.Redis().keys('*')