data structures - Composite key / secondary indexing strategy in Redis -
say have data of following sort want store in redis:
* uuid * state (e.g. processed, waiting_for_response) * […] other vals
the uuid
or state
2 variables ever need query on
- what data structure in redis suited this?
- how go structuring keys?
okay, not sure understand going try go it.
assuming need entities state processed
can use sets these:
sadd processed 123-abcd-4567-0000
then can find entities processed
state. you'll same each state want.
smembers processed
now you'll want have hash entities , values:
hset 123-abcd-4567-0000 state processed hset 123-abcd-4567-0000 otherproperty valuedata
this set "state" in hash uuid processed (you'll need figure out how keep these in sync, can use scripts or handle in code)
so in summary have 2 major structures:
- sets store state uuid information
- thus have 1 set per state
- hashes store uuid properties information
- thus have 1 hash per entity
example hash
123-abcd-4567-0000 => { state: processed, active: true } 987-zxy-1234-0000 => { state: processed, active: false }
but please clarify more if doesn't seem fit.
if want reduce key space since hashes per entity can can create hash per attribute instead:
hset states 123-abcd-4567-0000 processed
thus have hash per attribute , key uuid , value value of property hash key.
example hash
state => { 123-abcd-4567-0000: processed, 987-zxy-1234-0000: processed } active => { 123-abcd-4567-0000: true, 987-zxy-1234-0000: false }
Comments
Post a Comment