doulu1914 2014-08-27 14:00
浏览 271
已采纳

如何使用Redis进行Postgresql的LRU缓存?

I'm new to Redis and wondering how to use Redis and PostgreSql together — specifically using Redis just for LRU caching in Postgres.

Is there any special configuration for connecting Redis to Postgres?

Then if I want to store data, should I store it in Postgres db? If so, what does Redis do?

Thanks.

  • 写回答

2条回答 默认 最新

  • dongtui4038 2014-08-27 19:32
    关注

    I think you misunderstand what memory stores like Redis or memcached can do for you.

    They are not connected to PostgreSQL or any other RDBMS. It is the job of your application to write the data in both stores: the permanent store (PostgreSQL in your case) and the transient one (Redis).

    Redis and memcached do not offer many connectivity features. For caching, they have a rather simple and unobtrusive behavior. The smart part to manage the cache is on application side, and it is your job to define it.

    You can imagine several strategies:

    • each time you write in the RDBMS, you write in the cache. Each time you need to read the data, read first in the cache. If nothing is found, read from the RDBMS and write it back to the cache.

    • each time you write in the RDBMS, you just invalidate the data in the cache (delete it). Each time you need to read the data, read first in the cache. If nothing is found, read from the RDBMS and write it back to the cache.

    The tricky part is to clearly define a policy regarding the consistency of the data (between the RDBMS and the cache).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)