Data modeling practices in Redis?

daveslab picture daveslab · Feb 5, 2011 · Viewed 17.2k times · Source

I've recently been getting into Redis and find it very appealing. I'd like to see how far I can push it's limits as a database. I read the Retwis tutorial and found it very interesting. I'm wondering if there are even more resources that give examples of data modeling in Redis? Perhaps something along the lines of a cookbook?

Thanks!

EDIT

So here are some links I've found so far. I'd really like to know some more:

Answer

The Real Bill picture The Real Bill · May 31, 2011

There is a catch in what you ask for: it all depends on your data.

Fundamentally Redis is a data structure server. How you structure your data depends almost entirely on what it is and how you need to access it. The simple and common cases are fairly well covered by the links you list.

Designing for Redis in my experience is more along the lines of "how simple is my structure?". Can you model your data via hash? If so, use the hash commands in Redis. Do you need to combine sets and key-values or hashes? Then do it the same in redis. Essentially, assume you were not using a database. If you did it entirely within your programming language and in memory, how would you model your data? Odds are that is how you'd do it in Redis - or close enough to figure the rest out.

That isn't to say that specific usage patterns will not emerge. I think they are starting to. For example a common question is about web access log storage/calculation and there are common patterns coming out of those efforts. Yet there again I expect them to essentially mirror in-memory structures common to programming languages such as hashes, sets, ordered sets, lists, key-value (ie. the variable), and atomic counters. Further, most will be specific to the program being written. I suspect that is why the cookbook is still sparse (that and it is still early).

I'd suggest joining the redis list and discussing particular needs there.