Skip to content

Instantly share code, notes, and snippets.

@tinogis
Last active January 13, 2022 07:47
Show Gist options
  • Save tinogis/35101e9efadda7b286168e9ca81f7029 to your computer and use it in GitHub Desktop.
Save tinogis/35101e9efadda7b286168e9ca81f7029 to your computer and use it in GitHub Desktop.
Delete finished jobs from redis. Better than a FLUSHBD
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