On Tue, Dec 15, 2009 at 7:02 PM, debasish <
ghosh.d...@gmail.com> wrote:
> Thanks a lot for the detailed response. From the response I think
> storing the map as top level key values will make sense. But I need to
> keep the following in mind :-
>
> 1. md5 of the keys, since I don't have control over the space issue
>
> 2. I need to carefully construct the key structure, since they may
> clash across maps. There will be multiple maps, but I can scope them
> properly if I use a :delimited key structure as you suggested
Like Michel said already, using base64 (or even md5 or sha1) you can
use a character that can't appear in the base64/md5/sha1 charset in
order to split the different parts of the keys without overlapping
problems.
> 3. regarding the values I am using a binary serialization of the
> object. I can use JSON as well and I have the machinery to access
> individual JSON fields - so no problems there. Using JSON will also
> save space, I guess, as u mentioned. But, yeah, sorting will be a
> problem.
For sorting you still have the sorted sets strategy, that after all is
the way to go when possible.
About JSON, it's all about your dataset, if memory is a *very*
important concern, JSON can save an impressive amount of space, even
if every-key-a-field is a more polite way to store data in theory.
Btw there are is something I want to implement in Redis hashes:
special encoding. The idea born with Sets, there is a plan to add
specially encoded sets that are very space efficient. For instance
when we have sets of integers what are preventing us from storing this
sets into a special very compact form? This is the same for hashes, if
we have an hash with 20 smal fields (both keys and values) like in
most practical usages, what will prevent us from storing this objects
in a special space-efficient way paying just a little CPU hint? And
this is fully transparent from the user point of view.
So soon Redis will get Hashes and Sets that are space efficient while
the semantic is fully opaque. The user will deal with a clean
environment of binary safe keys and strings, while under the hoods
Redis will encode the whole hash in a space efficient way. Given that
will'll do this only for small number of keys and short keys/values,
it will still be an O(1) business asymptotically.
Ok let's return back to the crude fact that we still miss this stuff :)
For now the best thing is: use JSON if you have a lot of objects, and
objects are small, and you can live without SORT but can use sorted
sets. Otherwise use a key for every field of every object.
> 4. In my use case there will be multiple maps and lists. I am thinking
> of implementing redis as one of the persistent backing stores for akka
> transactors. We already have Cassandra and MongoDB working there. So
> all strcutures stored in redis will have an overall transaction scope
> and the key namespace can be controlled by a transaction id. But I
> really don't have control over the space issue in keys.
>
> Is there anything above that looks a redis anti-pattern ?
Not really. It's a bit a strange use case as usually you can control
the key, but given that in this specific context you can't I think
there isn't any anti pattern here.
For any help, I'm here.