【问题标题】:Using redis as an LRU cache for postgres使用 redis 作为 postgres 的 LRU 缓存
【发布时间】:2014-07-05 05:24:30
【问题描述】:

我有 postgres 9.3 db,我想使用 redis 缓存调用数据库(基本上就像 memcached)。我关注了这些docs,这意味着我基本上已经将redis配置为LRU缓存。但我不确定下一步该怎么做。如何告诉 redis 跟踪对数据库的调用并缓存它们的输出?我怎么知道它在工作?

【问题讨论】:

  • 使用 Rails 或哪个应用程序框架?
  • @nort 使用烧瓶 + sql alchemy + postgres
  • 这个问题很模糊。保存到数据库时,也将数据保存到redis。而当你需要读取时,从redis读取,如果不存在,从DB读取。
  • @bernie2436 您是否有任何层要写入 db 或者您正在为这个东西编写自己的代码??

标签: redis


【解决方案1】:

在伪代码中:

see if redis has the record by 'record_type:record_id'
if so return the result
if not then query postgres for the record_id in the record_type table
store the result in redis by 'record_type:record_id'
return the result

这可能必须是您正在使用的查询引擎的自定义适配器。

【讨论】:

  • 所以我必须手动写出对 redis 的调用。没有更高层次的抽象?
  • 对此一无所知,但它看起来正是我所需要的。谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-07-14
  • 1970-01-01
  • 2015-01-18
  • 2015-12-25
  • 2014-10-21
  • 1970-01-01
  • 1970-01-01
  • 2013-04-16
相关资源
最近更新 更多