parent = {
child0: {
data1:'foo',
data2: 'bar'
},
child1: {
data1:'foo',
data2: 'bar'
},
child2: {
data1:'foo',
data2: 'bar'
}
}
At first I was thinking I would set a parent:child key since I will need that data individually of its siblings. In some instances though, I will need to return all of the data within parent.
Should I just put the whole object in a parent key?
Are there downsides to this if a lot of gets and sets may only be for one of it’s children?
Is there a way to call all parent data with a parent:child schema?
Thanks!
Try a hash – that gives you HGET to get just one child and HGETALL to get all of them.
Storing the whole object as JSON in a single key is also valid though, and keeps your code simple if your usage is a good fit. If the numbers aren’t too large, it may make sense to always retrieve the whole object even when you only need to display one child object.
The main reason to avoid storing complex objects in a single key is write conflicts – if two connections can modify different children of one object at the same time a hash will be much less trouble.