Skip to content

Commit

Permalink
Merge pull request #1064 from getredash/fix/keys_cleanup
Browse files Browse the repository at this point in the history
Fix: old task trackers were not really removed
  • Loading branch information
arikfr committed May 19, 2016
2 parents e20a005 + b2e2277 commit 3f90dd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion redash/tasks/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def prune(cls, list_name, keep_count):

remove_count = count - keep_count
keys = redis_connection.zrange(list_name, 0, remove_count - 1)
redis_connection.delete(keys)
redis_connection.delete(*keys)
redis_connection.zremrangebyrank(list_name, 0, remove_count - 1)

return remove_count
Expand Down
9 changes: 8 additions & 1 deletion tests/tasks/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ class TestPrune(TestCase):
def setUp(self):
self.list = "test_list"
redis_connection.delete(self.list)
self.keys = []
for score in range(0, 100):
redis_connection.zadd(self.list, score, 'k:{}'.format(score))
key = 'k:{}'.format(score)
self.keys.append(key)
redis_connection.zadd(self.list, score, key)
redis_connection.set(key, 1)

def test_does_nothing_when_below_threshold(self):
remove_count = QueryTaskTracker.prune(self.list, 100)
Expand All @@ -22,3 +26,6 @@ def test_removes_oldest_items_first(self):

self.assertEqual(redis_connection.zscore(self.list, 'k:99'), 99.0)
self.assertIsNone(redis_connection.zscore(self.list, 'k:1'))

for k in self.keys[0:50]:
self.assertFalse(redis_connection.exists(k))

0 comments on commit 3f90dd9

Please sign in to comment.