Redis 可以写出到像 PostgreSQL 这样的数据库吗? [英] Can Redis write out to a database like PostgreSQL?

查看:27
本文介绍了Redis 可以写出到像 PostgreSQL 这样的数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 PostgreSQL 的时间最长.我所有的数据都保存在 Postgres 中.我最近研究了 redis,它有很多强大的功能,否则在 Django (python) 中需要几行代码才能完成.只要运行它的机器不停机,Redis 数据就是持久的,您可以将其配置为每 1000 个键或每 5 分钟左右将其存储的数据写出到磁盘,具体取决于您的选择.

I've been using PostgreSQL for the longest time. All of my data lives inside Postgres. I've recently looked into redis and it has a lot of powerful features that would otherwise take a couple of lines in Django (python) to do. Redis data is persistent as long the machine it's running on doesn't go down and you can configure it to write out the data it's storing to disk every 1000 keys or every 5 minutes or so depending on your choice.

Redis 将成为一个很好的缓存,它肯定会取代我用 Python 编写的许多功能(对用户的帖子进行投票,查看他们的朋友列表等......).但我担心的是,所有这些数据都需要转换为 postgres.我不相信将这些数据存储在 redis 中.我将 redis 视为一种用于快速检索信息的临时存储解决方案.它非常快,远远超过对 postgres 进行重复查询.

Redis would make a great cache and it would certainly replace a lot of functions I have written in python (up voting a user's post, viewing their friends list etc...). But my concern is, all of this data would some how need to be translated over to postgres. I don't trust storing this data in redis. I see redis as a temporary storage solution for quick retrieval of information. It's extremely fast and this far outweighs doing repetitive queries against postgres.

我假设我可以在技术上将 redis 数据写入数据库的唯一方法是 save() 我从 redis 的get"查询中通过 Django 到 postgres 数据库的任何内容.

I'm assuming the only way I could technically write the redis data to the database is to save() whatever I get from the 'get' query from redis to the postgres database through Django.

这是我能想到的唯一解决方案.您知道此问题的其他解决方案吗?

That's the only solution I could think of. Do you know of any other solutions to this problem?

推荐答案

Redis 越来越多地用作缓存层,很像更复杂的 memcached,并且在此角色中非常有用.您通常将 Redis 用作直写缓存,用于存储您希望持久化的数据,并回写用于您可能想要积累然后批量写入的数据(您可以承受丢失最近的数据).

Redis is increasingly used as a caching layer, much like a more sophisticated memcached, and is very useful in this role. You usually use Redis as a write-through cache for data you want to be durable, and write-back for data you might want to accumulate then batch write (where you can afford to lose recent data).

PostgreSQL 的 LISTENNOTIFY 系统对于执行选择性缓存失效非常有用,让您在 PostgreSQL 中更新记录时从 Redis 中清除它们.

PostgreSQL's LISTEN and NOTIFY system is very useful for doing selective cache invalidation, letting you purge records from Redis when they're updated in PostgreSQL.

要将其与 PostgreSQL 结合,您将找到 Andrew Dunstain 和 Dave Page 正在研究的 Redis 外部数据包装器提供程序 非常有趣.

For combining it with PostgreSQL, you will find the Redis foreign data wrapper provider that Andrew Dunstain and Dave Page are working on very interesting.

我不知道有什么工具可以使 Redis 成为 PostgreSQL 的透明写回缓存.他们的数据模型可能太不同,无法正常工作.通常,您将更改写入 PostgreSQL 并使用侦听/通知缓存管理器工作器使它们的 Redis 缓存条目无效,或者您在 Redis 中排队更改,然后让您的应用读取它们并将它们分块写入 Pg.

I'm not aware of any tool that makes Redis into a transparent write-back cache for PostgreSQL. Their data models are probably too different for this to work well. Usually you write changes to PostgreSQL and invalidate their Redis cache entries using listen/notify to a cache manager worker, or you queue changes in Redis then have your app read them out and write them into Pg in chunks.

这篇关于Redis 可以写出到像 PostgreSQL 这样的数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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