-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathqmk_redis.py
More file actions
33 lines (24 loc) · 749 Bytes
/
qmk_redis.py
File metadata and controls
33 lines (24 loc) · 749 Bytes
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
import json
from os import environ
from redis import Redis
from rq import Queue
# Configuration
REDIS_HOST = environ.get('REDIS_HOST', 'redis.qmk-api')
REDIS_TIMEOUT = int(environ.get('REDIS_TIMEOUT', 180))
# Objects we need to instaniate
redis = Redis(REDIS_HOST)
rq = Queue(connection=redis)
def enqueue(func, timeout=REDIS_TIMEOUT, *args, **kwargs):
"""Insert a job into RQ.
"""
return rq.enqueue(func, job_timeout=timeout, *args, **kwargs)
def get(key):
"""Fetches a JSON serialized object from redis.
"""
data = redis.get(key)
if data:
return json.loads(data.decode('utf-8'))
def set(key, value):
"""Writes a JSON serialized object to redis.
"""
return redis.set(key, json.dumps(value))