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

如何使用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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。