I want to append a dictionary in a Redis cache.
I don't have any problem with adding a dictionary into the Redis but I cannot append several dictionaries into the Redis.
Here's an example:
import redis
cli = redis.Redis('localhost')
list_of_dict = [ # dummy
{
'tags': {'module': 'destructor', 'station': 'SNMP'},
'metric_name': 'destructor',
'value': -8555,
'time': '2018-11-13T15:25:07'
},
{
'tags': {'module': 'voltage', 'station': 'SNMP'},
'metric_name': 'voltage',
'value': 222,
'time': '2018-11-13T15:25:09'
}
]
from pprint import pprint
for ld in list_of_dict:
cli.hmset("pythonDict", ld)
# conn.append(key, val) # Needs a key value.
pprint(cli.hgetall("pythonDict"))
In the above code snippet .hmset() writes only the last element/dict of list_of_dict into the Redis (override) and .append() needs the a key,val.
How can I write/append the two dictionaries of list_of_dict on Redis and retrieve them?
