Search code examples
voldemort

Correct usage of Voldemort as key-value pair?


I am trying to understand, how can Voldermort be used? Say, I have this scenario:

Since, Voldemort is a key-value pair. I need to fetch a value (say some text) on the basis of 3 parameters.

So, what will be the key in this case? I cannot use 3 keys for 1 value right, but that value should be search able on the basis of those 3 parameters.

Am I making sense?

Thanks

EDIT1

eg: A blog system. A user posts a blog: User's data stored: Name, Age and Sex The blog content (text) is stored.

Now, I need to use Voldemort here, if a user searches from the front end for all the blog posts by Sex: Male

Then, my code should query voldemort and return all the "blog content (text)" which have Sex as Male.

So, as per my understanding:

Key = Name, Age and Sex
Value = Text

I am using Java.


Solution

  • Edited answer to fit with example added to question:

    The thing to understand about Voldemort is that it's a very simple key-value store. As far as I know about it, the only thing you can do is store a value under a key, and then fetch those values by key. So for your example case, if you really want to use Voldemort, you have a few options.

    So, for example, you've said that you're storing data for users. So, you might have something like this:

    Key = user-Chad
    Value = Name:Chad Birch, Age:26, Sex:Male
    

    Now, if I want to post a new blog post, you also need to store that under a key. So you could do something like this:

    Key = blog-Chad1
    Value = Here is my very first blog post.
    

    Now, your problem is that you need some way to look up all the blog posts made by users with Sex:Male, but there's no way to get that data directly. At this point, you have to either:

    1. Pull out every single user, check if they're male, and if they are, pull out their blog posts.
    2. Start storing more stuff in other key-value pairs so that you can look this up.

    To implement #2, you could add another pair like this:

    Key = search-Sex:Male
    Value = Chad1 Chad2 Steve1 ...
    

    Then, when someone does a search for Sex:Male, you pull out the value for this, split it up, and then go fetch all those blog posts.

    Does that make sense? Using a k-v store is quite a bit different from a database, because you lose all these relational abilities.