使用 redis 作为 postgres 的 LRU 缓存 [英] Using redis as an LRU cache for postgres

查看:69
本文介绍了使用 redis 作为 postgres 的 LRU 缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 postgres 9.3 db,我想使用 redis 来缓存对数据库的调用(基本上类似于 memcached).我遵循了这些 docs,这意味着我基本上已经将 redis 配置为用作 LRU 缓存.但我不确定接下来要做什么.我如何告诉 redis 跟踪对数据库的调用并缓存它们的输出?我怎么知道它在工作?

I have postgres 9.3 db and I want to use redis to cache calls the the DB (basically like memcached). I followed these docs, which means I have basically configured redis to work as an LRU cache. But am unsure what to do next. How do I tell redis to track calls to the DB and cache their output? How can I tell it's working?

推荐答案

伪代码:

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

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

This might have to be a custom adapter for the query engine that you are using.

这篇关于使用 redis 作为 postgres 的 LRU 缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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