-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.py
43 lines (26 loc) · 833 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
import redis
from walrus import Cache, Database
db = redis.Redis(db=0)
cache = Cache(Database(host='localhost', port=6379, db=0))
@cache.cached(timeout=3600)
def get_id(uuid):
return db.hget(uuid, 'id').decode()
@cache.cached(timeout=3600)
def get_passwd(uuid):
return db.hget(uuid, 'passwd').decode()
def get_tasks_from_db(uuid):
""" Returns `set` of tasks names """
tasks = db.smembers(f'{uuid}:tasks')
return set(task.decode() for task in tasks)
def set_id(uuid, id):
get_id.bust()
db.hset(uuid, 'id', id)
def set_passwd(uuid, passwd):
get_passwd.bust()
db.hset(uuid, 'passwd', passwd)
def set_tasks(uuid, set_of_tasks):
for task in set_of_tasks:
db.sadd(f'{uuid}:tasks', task)
def remove_task(uuid, task):
db.srem(f'{uuid}:tasks', task)