redisactions.py 1.54 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
# setting up redis database
redisdb = redis.from_url("redis://localhost:6379/0", db=0)
20

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

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

30
    return redisdb.get("gcdict") is not None and success
31

32

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

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

42
    return redisdb.get("livedict") is not None and success
43

44

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

50
    return redisdb.lrange("dbupdatelog", 0, 0) == logstring