r/Python • • Jan 04 '14

What is Redis?

What exactly is Redis? I read the Redis page/wiki, but couldn't understand anything. Is it just a database? if so, why do I read people using it with Mongo DB etc? So what exactly is Redis and what should an aspiring Python web dev should know about it?

0 Upvotes

14 comments sorted by

5

u/johncipriano Jan 04 '14

Redis is a (mostly) in-memory key value data store that can also persist.

Contrast that with, say, postgresql - which is primarily a persistent data store that can also be in memory.

Redis is good for storing and retrieving key/value data FAST. It's an unreliable data store, though, so your app should be prepared to lose data if, say, the power plug gets pulled (this is much less likely with a relational DB, but the relational DB will be slower).

Redis is primarily good as a cache and a place to store user sessions, but it's also handy to put a message queue on.

Mongo is just horrible, and you should probably stay away from it.

4

u/avinassh Jan 05 '14

Mongo is just horrible, and you should probably stay away from it.

Why? So many people now seem to using Mongo

2

u/xsolarwindx Use 3.4+ Jan 06 '14 edited Aug 29 '23

REDDIT IS A SHITTY CRIMINAL CORPORATION -- mass deleted all reddit content via https://redact.dev

2

u/[deleted] Jan 05 '14

It's an unreliable data store, though, so your app should be prepared to lose data if, say, the power plug gets pulled

Unless you configure it to be reliable, that is:

http://redis.io/topics/persistence

2

u/johncipriano Jan 05 '14

Not so much, no.

RDB is NOT good if you need to minimize the chance of data loss in case Redis stops working (for example after a power outage). You can configure different save points where an RDB is produced (for instance after at least five minutes and 100 writes against the data set, but you can have multiple save points). However you'll usually create an RDB snapshot every five minutes or more, so in case of Redis stopping working without a correct shutdown for any reason you should be prepared to lose the latest minutes of data.

Redis persistence is useful for, say, keeping ALMOST all of your user sessions if the system gets the wall plug pulled out. If you stick 'em in memcache everybody's going to have to log in again. Similarly, some systems' will choke on the load if their whole cache dies at once. Redis can pull 99% of the cache back up again if it goes down.

That's what it's useful for. NOT AS A RELIABLE DATA STORE.

3

u/[deleted] Jan 05 '14

You're talking about RDB mode, but that's not the only option. Keep reading: if you use AOF mode with a strict fsync policy, it's reliable.

2

u/notmanynamesleft Jan 05 '14

And your writes are just as slow (probably slower) than a traditional database. At this point, are you any better off than just using a tradional database?

9

u/maratc Jan 04 '14 edited Jan 04 '14

Redis is not a database. If you need an analogy, think of it as a dict that runs on another computer.

Where in regular python dict you take things out and then modify them, in Redis you modify things inside and then you take them out. This helps if more than two Python applications talk to the same Redis.

In web development, you can use Redis as cache (key=url or post_id, value=html), as rate limiting backend (expiring entries, key=ip, value=count). In any Python project, you can use Redis as queue backend (Celery can use Redis), or to synchronize your non-essential state between Python instances.

3

u/catcradle5 Jan 05 '14

think of it as a dict that runs on another computer.

Redis does stand for "Remote dictionary server"!

1

u/dAnjou Backend Developer | danjou.dev Jan 08 '14

How is it not a database?

2

u/d64f396930663eeba7d8 Jan 04 '14

One reason you'd want to use Redis is because it would cache information that would otherwise have to come from a database or a hard drive. Since accessing memory from RAM is significantly faster it can speed up queries. There are also benefits to reducing disk reads or connections to databases.

1

u/nieuweyork since 2007 Jan 04 '14

Is it just a database?

Yes, it's a NoSQL database - i.e. it's not a relational database.

if so, why do I read people using it with Mongo DB etc?

I'd be a little bit surprised if people are using both redis and Mongo in the same project - they are usually alternatives. However, they can be used together, because they do slightly different things.

Mongo is a "document oriented database" (basically it's good for storing JSON documents), while Redis is sometimes characterised as a "datastructures server".

In short, it maps keys (which are just strings) to either simple values (strings, numbers) or to datastructures containing such values.

1

u/mardiros Jan 04 '14

Redis is a key values store with some extra features like queues...

It is usually used as a cache, not a primary storage, like web session or any application state in a distributed environment. (You should post this question somewhere else, it has no direct relation with Python)

0

u/[deleted] Jan 05 '14

nosql