redisactions.py 1.55 KB
Newer Older
1 2 3
# python imports
import datetime

4
# other imports
5 6 7 8 9 10 11 12 13
import redis

# I'm thinking we store a couple things
# first: a key-value where the value is the dictlist
# second: a k-v for a list of errored events

# use rpush(key, value) to append a dblist (rpushx() to check if it exists)
# use del(key) to remove a k-v

14
# so everytime we run parscript or gcscript we want to run a dbfill()
15 16 17
# function. and every time we find an error we want to run a dberrorfill()
# function.

18

19 20
# setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0)
21

22

23
# this will update the live dictlist and the cachedate
24
# returns true if the dictlist is not empty, false otherwise
25
def gc_db_fill(dictlist):
26 27 28 29 30
    success = redisdb.set("gcdict", dictlist)

    log = str(datetime.datetime.now())
    redisdb.set("gccachedate", log)
    success = redisdb.get("gccachedate") == log and success
31

32
    return redisdb.get("gcdict") is not None and success
33

34

35
# saves new dictlist in place of previous 25Live dictlist
36
# returns true if the dictlist is not empty, false otherwise
37
def live_db_fill(dictlist):
38 39 40 41 42
    success = redisdb.set("livedict", dictlist)

    log = str(datetime.datetime.now())
    redisdb.set("livecachedate", log)
    success = redisdb.get("livecachedate") == log and success
43

44
    return redisdb.get("livedict") is not None and success
45

46

47 48
# appends the log string to the head of our update long
# returns true if the head is the newest update
49
def append_to_update_log(logstring):
50
    redisdb.lpush("dbupdatelog", logstring)
51

52
    return redisdb.lindex("dbupdatelog", 0) == logstring