import redis, os UPLOAD_DIR = '/storage/' r = redis.StrictRedis() pubsub = r.pubsub() pubsub.psubscribe("*") for msg in pubsub.listen(): if msg['channel'].decode('utf-8') == '__keyevent@0__:expired': os.remove(UPLOAD_DIR + msg['data'].decode('utf-8')) print("Deleted file " + msg['data'].decode('utf-8'))