diff --git a/rq/results.py b/rq/results.py index a6dafde..8ff770d 100644 --- a/rq/results.py +++ b/rq/results.py @@ -169,7 +169,10 @@ class Result(object): if pipeline is None: self.id = result.decode() if ttl is not None: - connection.expire(key, ttl) + if ttl == -1: + connection.persist(key) + else: + connection.expire(key, ttl) return self.id def serialize(self): diff --git a/tests/test_results.py b/tests/test_results.py index 4f705f5..9bc1b9e 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -214,3 +214,25 @@ class TestScheduledJobRegistry(RQTestCase): job = queue.enqueue(div_by_zero) self.assertEqual(job.latest_result().type, Result.Type.FAILED) + + def test_job_return_value_result_ttl_infinity(self): + """Test job.return_value when queue.result_ttl=-1""" + queue = Queue(connection=self.connection, result_ttl=-1) + job = queue.enqueue(say_hello) + + # Returns None when there's no result + self.assertIsNone(job.return_value()) + + Result.create(job, Result.Type.SUCCESSFUL, ttl=-1, return_value=1) + self.assertEqual(job.return_value(), 1) + + def test_job_return_value_result_ttl_zero(self): + """Test job.return_value when queue.result_ttl=0""" + queue = Queue(connection=self.connection, result_ttl=0) + job = queue.enqueue(say_hello) + + # Returns None when there's no result + self.assertIsNone(job.return_value()) + + Result.create(job, Result.Type.SUCCESSFUL, ttl=0, return_value=1) + self.assertIsNone(job.return_value())