Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data modeling practices in Redis? [closed]

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:

like image 301
daveslab Avatar asked Feb 05 '11 16:02

daveslab


People also ask

Can we persist data in Redis?

Within Redis, there are two different ways of persisting data to disk. One is a method called snapshotting that takes the data as it exists at one moment in time and writes it to disk. The other method is called AOF, or append—only file, and it works by copying incoming write commands to disk as they happen.

Does Redis lose data on restart?

If a Redis server that only stores data in RAM is restarted, all data is lost. To prevent such data loss, there needs to be some mechanism for persisting the data to disk; Redis provides two of them: snapshotting and anappend-only file, or AOF.

Is Redis good for persistent?

Redis isn't the best fit for persistent storage as it's mainly performance focused. Redis is really more suitable for reliable in-memory storage/cacheing of current state data, particularly for allowing scalability by providing a central source for data used across multiple clients/servers.


2 Answers

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.

like image 197
The Real Bill Avatar answered Oct 22 '22 03:10

The Real Bill


Here are a two more resources that could be helpful for Redis data modeling:

  • http://www.paperplanes.de/2010/2/16/a_collection_of_redis_use_cases.html - a bit old but very accurate, 11 examples of Redis commands and how they are used correctly in data modelling
  • http://www.slideshare.net/dvirsky/introduction-to-redis - a presentation by Dvir Volk, a well-known figure in the Redis community, he explains what you can do with Redis including advanced things like pub/sub and transactions, with a use case example of a simple social feed
like image 31
Lea Krause Avatar answered Oct 22 '22 02:10

Lea Krause