How to cache a entire table in Redis,either to cache the entire table for one single key or each row with a different key.If we cache the entire table for a single key the entire table will be returned every time even if i need a single record as my output.I am quite new to Redis caching and not clear how to cache a entire table.
1 Answer 1
You should use a Redis Hash, so you can index the row by its key and retrieve an element in O(1).
For example, using redis-cli (you can try it in http://try.redis.io).
Insert the row elements to the hash in a key named "table":
> HSET table 100 "serialized row with id 100" 
(integer) 0
> HSET table 101 "serialized row with id 101" 
(integer) 1
Get the value associated with a row key.
> HGET table 100
"serialized row 100"
Get all the values in the hash:
> HGETALL table
1) "100"
2) "serialized row 100"
3) "101"
4) "serialized row 101"