diff --git a/rq/queue.py b/rq/queue.py index 359aa1a5..a006071e 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -42,6 +42,10 @@ class Queue(object): """Returns the Redis key for this Queue.""" return self._key + def empty(self): + """Removes all messages on the queue.""" + conn.delete(self.key) + def is_empty(self): """Returns whether the current queue is empty.""" return self.count == 0 diff --git a/tests/test_queue.py b/tests/test_queue.py index d1fa44ec..71959dd9 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -28,7 +28,20 @@ class TestQueue(RQTestCase): self.assertNotEquals(q2, q3) - def test_queue_empty(self): + def test_empty_queue(self): + """Emptying queues.""" + q = Queue('example') + + self.testconn.rpush('rq:queue:example', 'foo') + self.testconn.rpush('rq:queue:example', 'bar') + self.assertEquals(q.is_empty(), False) + + q.empty() + + self.assertEquals(q.is_empty(), True) + self.assertIsNone(self.testconn.lpop('rq:queue:example')) + + def test_queue_is_empty(self): """Detecting empty queues.""" q = Queue('example') self.assertEquals(q.is_empty(), True)