Skip to content

Commit

Permalink
Merge branch 'main' into prod-lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
brycegoh committed Nov 25, 2023
2 parents 79e3fb3 + 6477d2f commit f3a5aaa
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def lambda_handler(event, context):
try:
redisClient = redis.Redis(host=REDIS_ENDPOINT, port=6379, decode_responses=True)
except Exception as e:
print(f"Error connecting to redis: {e}")
return {
'statusCode': 500,
'body': json.dumps({
'error': 'Error connecting to redis',
'error_message': str(e)
})
}

rowId = event.get('rowId')
temp = event.get('temp')
Expand Down Expand Up @@ -64,7 +70,7 @@ def lambda_handler(event, context):
'body': json.dumps({
'fire_probability': fire_probability,
'r_value': r_value,
'redis_val': test_redis()
'redis_val': test_redis(redisClient)
})
})

Expand Down Expand Up @@ -114,27 +120,27 @@ def get_r_value(temp_arr, humidity_arr):
return r_actual

# ================== Redis helper functions ==================
def set_timestamp(nodeId: str):
key = f"node_{nodeId}_timestamp"
five_minutes = 60 * 5
redisClient.set(key, "1")
redisClient.expire(key, five_minutes)

def set_flag(nodeId: str):
key = f"node_{nodeId}_flag"
redisClient.set(key, "1")

def get_flag(nodeId: str):
key = f"node_{nodeId}_flag"
# return None if does not exists
return redisClient.get(key)

def get_timestamp(nodeId: str):
key = f"node_{nodeId}_timestamp"
# return None if does not exists
return redisClient.get(key)

def test_redis():
# def set_timestamp(nodeId: str):
# key = f"node_{nodeId}_timestamp"
# five_minutes = 60 * 5
# redisClient.set(key, "1")
# redisClient.expire(key, five_minutes)

# def set_flag(nodeId: str):
# key = f"node_{nodeId}_flag"
# redisClient.set(key, "1")

# def get_flag(nodeId: str):
# key = f"node_{nodeId}_flag"
# # return None if does not exists
# return redisClient.get(key)

# def get_timestamp(nodeId: str):
# key = f"node_{nodeId}_timestamp"
# # return None if does not exists
# return redisClient.get(key)

def test_redis(redisClient):
key = "test"
redisClient.set(key, "1")
res = redisClient.get(key)
Expand Down

0 comments on commit f3a5aaa

Please sign in to comment.