Use a redis set to store queue names, instead of relying on the redis "keys" method,

which does not perform well on large databases.
main
Rob Harrigan 11 years ago
parent 60dba7c106
commit c08b96e027

@ -18,6 +18,7 @@ def compact(lst):
@total_ordering @total_ordering
class Queue(object): class Queue(object):
redis_queue_namespace_prefix = 'rq:queue:' redis_queue_namespace_prefix = 'rq:queue:'
redis_queues_keys = 'rq:queues'
@classmethod @classmethod
def all(cls, connection=None): def all(cls, connection=None):
@ -29,7 +30,7 @@ class Queue(object):
def to_queue(queue_key): def to_queue(queue_key):
return cls.from_queue_key(as_text(queue_key), return cls.from_queue_key(as_text(queue_key),
connection=connection) connection=connection)
return list(map(to_queue, connection.keys('%s*' % prefix))) return list(map(to_queue, connection.smembers(cls.redis_queues_keys)))
@classmethod @classmethod
def from_queue_key(cls, queue_key, connection=None): def from_queue_key(cls, queue_key, connection=None):
@ -51,6 +52,7 @@ class Queue(object):
self._key = '%s%s' % (prefix, name) self._key = '%s%s' % (prefix, name)
self._default_timeout = default_timeout self._default_timeout = default_timeout
self._async = async self._async = async
self.connection.sadd(self.redis_queues_keys, self.key)
@property @property
def key(self): def key(self):

@ -251,6 +251,17 @@ class TestQueue(RQTestCase):
job = q.enqueue(say_hello) job = q.enqueue(say_hello)
self.assertEqual(job.status, Status.QUEUED) self.assertEqual(job.status, Status.QUEUED)
def test_all_queues(self):
"""All queues"""
q = Queue('first-queue')
r = Queue('second-queue')
s = Queue('third-queue')
all = Queue.all()
self.assertEquals(len(all), 3)
names = [q.name for q in all]
self.assertTrue('first-queue' in names)
self.assertTrue('second-queue' in names)
self.assertTrue('third-queue' in names)
class TestFailedQueue(RQTestCase): class TestFailedQueue(RQTestCase):
def test_requeue_job(self): def test_requeue_job(self):

Loading…
Cancel
Save