1

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?

4
  • using rails or which application framework? Commented Jul 5, 2014 at 5:28
  • @nort using flask + sql alchemy + postgres Commented Jul 5, 2014 at 5:30
  • the question is very vague. when you save to DB, save the data to redis too. and when you need to read, read from redis, and if it is not there, read from the DB. Commented Jul 5, 2014 at 5:31
  • @bernie2436 did you get any layer to write to db or you are writing your own code for this thing ?? Commented Apr 4, 2017 at 10:55

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

so I have to write out the calls to redis manually. there is no higher level abstraction?
did not know about that but it looks like just what I need. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.