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

查看:274
本文介绍了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用作 write-through 缓存,对于可能要累积然后批量写入的数据,可以使用 write-back 负担丢失最近的数据)。

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的 LISTEN NOTIFY system对于执行选择性缓存失效非常有用,可以让您在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天全站免登陆