From 244851c7cc818f6471bc5c66ff595e73e5d14287 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 23 Nov 2022 15:04:39 +0000 Subject: [PATCH] jobs: remove 'jobs' list, and use 'jobs:' prefix Less complexity, easier to add redis-native TTL --- selfprivacy_api/jobs/__init__.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/selfprivacy_api/jobs/__init__.py b/selfprivacy_api/jobs/__init__.py index 7c16afd..4fa820c 100644 --- a/selfprivacy_api/jobs/__init__.py +++ b/selfprivacy_api/jobs/__init__.py @@ -69,7 +69,6 @@ class Jobs: jobs = Jobs.get_jobs() for job in jobs: r.delete(redis_key_from_uuid(job.uid)) - r.delete("jobs") @staticmethod def add( @@ -99,7 +98,6 @@ class Jobs: ) r = RedisPool().get_connection() store_job_as_hash(r, redis_key_from_uuid(job.uid), job) - r.lpush("jobs", redis_key_from_uuid(job.uid)) return job @staticmethod @@ -117,7 +115,6 @@ class Jobs: r = RedisPool().get_connection() key = redis_key_from_uuid(job_uuid) r.delete(key) - r.lrem("jobs", 0, key) return False @staticmethod @@ -151,7 +148,7 @@ class Jobs: r = RedisPool().get_connection() key = redis_key_from_uuid(job.uid) - if exists_sync(r, key): + if r.exists(key): store_job_as_hash(r, key, job) return job @@ -163,7 +160,7 @@ class Jobs: """ r = RedisPool().get_connection() key = redis_key_from_uuid(uid) - if exists_sync(r, key): + if r.exists(key): return job_from_hash(r, key) return None @@ -173,7 +170,7 @@ class Jobs: Get the jobs list. """ r = RedisPool().get_connection() - jobs = r.lrange("jobs", 0, -1) + jobs = r.keys("jobs:*") return [job_from_hash(r, job_key) for job_key in jobs] @staticmethod @@ -203,7 +200,7 @@ def store_job_as_hash(r, redis_key, model): def job_from_hash(r, redis_key): - if exists_sync(r, redis_key): + if r.exists(redis_key): job_dict = r.hgetall(redis_key) for date in [ "created_at", @@ -218,7 +215,3 @@ def job_from_hash(r, redis_key): return Job(**job_dict) return None - - -def exists_sync(r, key): - return r.exists(key)