bernie2436
bernie2436

Reputation: 23901

Using redis as an LRU cache for postgres

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?

Upvotes: 1

Views: 3424

Answers (1)

nort
nort

Reputation: 1615

In pseudo code:

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.

Upvotes: 4

Related Questions