I have file consisting of thousands of lines(each containing 3 fields, first is a k length string, then a number, third another string) of form:-
k|1|r1
k|1|r2
k|2|r2
k1|1|r3
I load it using redis-py, by using:-
sadd('k:1', 'r1')
sadd('k:1', 'r2')
sadd('k:2', 'r2')
sadd('k1:1', 'r3')
to form a mapping like
{
"k:1" : ("r1", "r2"),
"k:2" : ("r2"),
"k1:1" : ("r3")
}
I intend to store the values of the form, by removing the repetitive information of k(which is a k length string common for the first 3 records):
{
"k": {
"1" : ("r1", "r2"),
"2" : ("r2")
}
"k1": {
"1" : ("r3")
}
}
I have the idea of storing the value of storing the set under a different key, which can act as value for k in the hash. Is there a better way than that?