Developer Journal: 15 April 2020

Posted on Wed 15 April 2020 in dev-journal

Spent some time today trying to use Redis as a way to store a python dictionary. Given my lack of understanding of Redis, I struggled with how to do this and ended up just making a new key with the new value I wanted to store.

So now while the related information has two different keys, I was able to store and extract the information that I needed in two calls instead of one.

Currently what that looks like when storing the data:

redis_client.hmset("prekey1:sharedkey", {tuple[0]: tuple[1]})
redis_client.hmset("prekey2:sharedkey", {tuple[0]: tuple[1]})

Then when retrieving the data:

data_1 = redis_client.keys("prekey1:*")
data_2 = redis_client.keys("prekey2:*")

# Loop through data
for key in data1:
    key = key.decode("utf-8")
    d1_list[key] = redis_client.hgetall(key)
for key in data2:
    key = key.decode("utf-8")
    d2_list[key] = redis_client.hgetall(key)

While this may not be the ideal solution, it works for what I am trying to do. Will need to dig further into Redis to understand how to store the data in the way I initially intended.