当我将PostgreSQL作为Django的数据库时,为什么要使用Redis? [英] Why Should I use Redis when I have PostgreSQL as my database for Django?

查看:133
本文介绍了当我将PostgreSQL作为Django的数据库时,为什么要使用Redis?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django应用,该应用当前托管在Amazon的EC2服务上。我有两台计算机,一台使用Django应用程序,另一台使用我的PostgreSQL数据库。到目前为止,它是坚如磐石的。

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.

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

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?

如何在PostgreSQL中使用它?

How can I use it with 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.

谢谢

推荐答案

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

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.

您可以将其包含在Django / Python项目中包装器,例如 redis-py

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

Redis的安装和使用非常简单,您可以在 redis-py 中查看示例。 Redis独立于任何关系数据库,因此您可以将其用于永久和/或临时缓存,计算或存储值。它可以帮助减少对PostgreSQL的查询,最终您可以按自己的方式使用它,并利用它来改善应用程序/体系结构。

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与Django

This similar question can help you Redis with Django

这篇关于当我将PostgreSQL作为Django的数据库时,为什么要使用Redis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆