1
votes

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?

1
using rails or which application framework? - nort
@nort using flask + sql alchemy + postgres - bernie2436
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. - akonsu
@bernie2436 did you get any layer to write to db or you are writing your own code for this thing ?? - Luv33preet

1 Answers

4
votes

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.