[erlang-questions] Key-value stores and value part
Max Bourinov
bourinov@REDACTED
Sat Feb 25 17:21:11 CET 2012
You can try something like this:
Key = term(),
Value =[{Key :: atom(), Value :: term()]
With this approach you can dynamically manage fields in your Value. Of
course some extra business logic and helper functions are needed.
Sent from my iPhone
On 25.02.2012, at 6:37, Vinayak Pawar <vinayakapawar@REDACTED> wrote:
Hi,
I've a key-value store. The value part is a tuple stored using
term_to_binary().
-record(some_rec, {e1, e2}).
Rec = #some_rec{e1 = E1, e2 = E2}
kv_store:put(Key, term_to_binary(Rec)).
I access the values in this key-value store as below:
case kv_store:get(Key) of
{ok, Bin} ->
#some_rec{} = Rec = binary_to_term(Bin),
do_some_work(Rec);
false ->
do_something_else(Key)
end.
Now there is change in my tuple structure. A new element/field is been
added to it:
-record(some_rec, {e1, e2, e3}).
Henceforth tuples with this new structure will get stored in the KV store.
This means, everytime I change the tuple structure, I need to run through
each key-value pair that has been stored using older tuple structure and
update the value part to be in sync with new tuple structure?
This gives a hint that I'm doing something wrong in the way I store the
values in schema-less KV store. Can you please help me figure out what is
wrong?
Question: is it possible to store values in KV store so that I don't have
to update the KV store whenever there is change in tuple structure? store
values in JSON form?
Regards,
Vinayak
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120225/fa56f5c3/attachment.htm>
More information about the erlang-questions
mailing list