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?
Asked
Active
Viewed 3,293 times
1
-
using rails or which application framework? – nort Jul 05 '14 at 05:28
-
@nort using flask + sql alchemy + postgres – bernie2436 Jul 05 '14 at 05: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. – akonsu Jul 05 '14 at 05:31
-
@bernie2436 did you get any layer to write to db or you are writing your own code for this thing ?? – Luv33preet Apr 04 '17 at 10:55
1 Answers
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.

nort
- 1,625
- 13
- 12
-
so I have to write out the calls to redis manually. there is no higher level abstraction? – bernie2436 Jul 05 '14 at 05:37
-
did not know about that but it looks like just what I need. thanks. – bernie2436 Jul 05 '14 at 17:44