Problem
I need a key-value store that can store values of the following form:
DS<DS<E>>
where the data structure
DScan be
either aList,SortedSetor anArrayand
Ecan be either aStringorbyte-array.
It is very expensive to generate this data and so once I put it into the store, I will only perform read queries on it. Essentially it is a complex object cache with no eviction.
Example Application
A (possibly bad, but sufficient to clarify) example of an application is storing tokenized sentences from a document where you need to be able to quickly access the qth word of the pth sentence given documentID. In this case, I would be storing it as a K-V pair as follows:
K - docID
V - List<List<String>>
String word = map.get(docID).get(p).get(q);
I prefer to avoid app-integrated Map solutions (such as EhCache within Java).
I have worked with Redis but it doesn’t appear to support the second layer of data-structure complexity. Any other K-V solutions that can help my use case?
Update:
I know that I could serialize/deserialize my object but I was wondering if there is any other solution.
In terms of platform choice you have two options – A full document database will support arbitrarily complex objects, but won’t have built in commands for working with specific data structures. Something like Redis which does have optimised code for specific data structures can’t support all possible data structures.
You can actually get pretty close with Redis by using ids instead of the nested data structure.
DS1<DS2<E>>becomesDS1<int>andDS2<E>, with theintfromDS1and a prefix giving you the key holdingDS2.With this structure you can access any
Ewith only two operations. In some cases you will be able to get that down to a single operation by knowing what the id of DS2 will be for a given query.