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

@ -251,6 +251,17 @@ class TestQueue(RQTestCase):
job = q.enqueue(say_hello)
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):
def test_requeue_job(self):

Loading…
Cancel
Save