Last active
January 13, 2022 07:47
-
-
Save tinogis/35101e9efadda7b286168e9ca81f7029 to your computer and use it in GitHub Desktop.
Delete finished jobs from redis. Better than a FLUSHBD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
r = redis.StrictRedis(host='redis') | |
l = r.keys('rq:job:*') | |
deleted_jobs = 0 | |
total_jobs = len(l) | |
for j in l: | |
if 'dependents' in j: | |
continue | |
print 'Job {}'.format(j) | |
status = r.hget(j, 'status') | |
print ' * STATE is {}'.format(status) | |
if status == 'finished' or status is None: | |
deleted_jobs += 1 | |
r.delete(j) | |
print ' * DELETED' | |
print('DELETED {} / {} Jobs'.format(deleted_jobs, total_jobs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment