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?
-
using rails or which application framework?nort– nort2014-07-05 05:28:24 +00:00Commented Jul 5, 2014 at 5:28
-
@nort using flask + sql alchemy + postgresbernie2436– bernie24362014-07-05 05:30:15 +00:00Commented 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.akonsu– akonsu2014-07-05 05:31:36 +00:00Commented 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 ??Luv33preet– Luv33preet2017-04-04 10:55:58 +00:00Commented Apr 4, 2017 at 10:55
Add a comment
|
1 Answer
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.
2 Comments
bernie2436
so I have to write out the calls to redis manually. there is no higher level abstraction?
bernie2436
did not know about that but it looks like just what I need. thanks.