Python 当我将 PostgreSQL 作为 Django 的数据库时,为什么要使用 Redis?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14989390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why Should I use Redis when I have PostgreSQL as my database for Django?
提问by deadlock
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
谢谢你
采纳答案by PepperoniPizza
Redisis 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 NoSQLdatabase, like Mongoand 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.
您可以使用包装器将它包含在您的 Django/Python 项目中,例如redis-py。
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 Redis

