当我有PostgreSQL作为Django的数据库时,为什么要使用Redis呢?

时间:2022-04-01 07:08:56

I've have a Django app that's currently hosted up on Amazon's EC2 service. I have two machines, one with the Django app and the other with my PostgreSQL database. So far it has been rock solid.

我有一个Django应用程序,它目前托管在Amazon的EC2服务上。我有两台机器,一个是Django应用程序,另一台是我的PostgreSQL数据库。到目前为止,它还是坚硬的岩石。

Many sources claim I should implement Redis into my stack, but what would be the purpose of implementing Redis with Django and Postgresql? How can I implement Redis in my Django code for example?

许多消息声称我应该在堆栈中实现Redis,但是用Django和Postgresql实现Redis的目的是什么呢?例如,我如何在我的Django代码中实现Redis ?

How can I use it with PostgreSQL?

如何在PostgreSQL中使用它?

These are all the questions I've been trying to find answers to so I came here hoping to get answers from the biggest and the best. I really appreciate any answers.

这些都是我一直在寻找答案的问题,所以我来到这里希望从最大的和最好的问题中得到答案。我非常感谢你的回答。

Thank You

谢谢你!

1 个解决方案

#1


38  

Redis is a key-value storage system that operates in RAM memory, it's like a "light database" and since it works at RAM memory level it's orders of magnitude faster compared to reading/writing to PostgreSQL or any other traditional Relational Database. Redis is a so-called NoSQL database, like Mongo and many others. It can't directly replace PostgreSQL, you still want permanent storage, but it works along with Relational Databases as an alternate storage system. You can use Redis if your IO operations start getting expensive and it's great for quick calculations and key-based queries.

Redis是一个在RAM内存中运行的键值存储系统,它就像一个“轻数据库”,由于它在RAM内存级别上工作,所以与对PostgreSQL或任何其他传统关系数据库的读写相比,它的速度要快很多。Redis是一个所谓的NoSQL数据库,像Mongo和其他许多数据库一样。它不能直接替换PostgreSQL,您仍然需要永久存储,但是它与关系数据库一起作为备用存储系统工作。如果IO操作开始变得昂贵,并且非常适合快速计算和基于键的查询,那么可以使用Redis。

You can include it in your Django/Python project with a wrapper, for example redis-py.

您可以使用包装器(例如redis-py)将它包含在Django/Python项目中。

Redis is very simple to install and use, you can check the examples at redis-py. Redis is independent from any Relational Database, that way you can use it for caching, calculating or storing values permanently and/or temporarily. It can help reduce querying to PostgreSQL, in the end you can use it the way you want and take advantage from it to improve your app/architecture.

Redis的安装和使用非常简单,您可以在Redis -py上查看示例。Redis独立于任何关系数据库,这样您就可以使用它进行缓存、计算或永久或临时存储值。它可以帮助减少对PostgreSQL的查询,最终您可以使用它,并利用它改进您的应用程序/体系结构。

This similar question can help you Redis with Django

这个类似的问题可以帮助你找到Django。

#1


38  

Redis is a key-value storage system that operates in RAM memory, it's like a "light database" and since it works at RAM memory level it's orders of magnitude faster compared to reading/writing to PostgreSQL or any other traditional Relational Database. Redis is a so-called NoSQL database, like Mongo and many others. It can't directly replace PostgreSQL, you still want permanent storage, but it works along with Relational Databases as an alternate storage system. You can use Redis if your IO operations start getting expensive and it's great for quick calculations and key-based queries.

Redis是一个在RAM内存中运行的键值存储系统,它就像一个“轻数据库”,由于它在RAM内存级别上工作,所以与对PostgreSQL或任何其他传统关系数据库的读写相比,它的速度要快很多。Redis是一个所谓的NoSQL数据库,像Mongo和其他许多数据库一样。它不能直接替换PostgreSQL,您仍然需要永久存储,但是它与关系数据库一起作为备用存储系统工作。如果IO操作开始变得昂贵,并且非常适合快速计算和基于键的查询,那么可以使用Redis。

You can include it in your Django/Python project with a wrapper, for example redis-py.

您可以使用包装器(例如redis-py)将它包含在Django/Python项目中。

Redis is very simple to install and use, you can check the examples at redis-py. Redis is independent from any Relational Database, that way you can use it for caching, calculating or storing values permanently and/or temporarily. It can help reduce querying to PostgreSQL, in the end you can use it the way you want and take advantage from it to improve your app/architecture.

Redis的安装和使用非常简单,您可以在Redis -py上查看示例。Redis独立于任何关系数据库,这样您就可以使用它进行缓存、计算或永久或临时存储值。它可以帮助减少对PostgreSQL的查询,最终您可以使用它,并利用它改进您的应用程序/体系结构。

This similar question can help you Redis with Django

这个类似的问题可以帮助你找到Django。