2

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.

asked Oct 22, 2015 at 6:22

1 Answer 1

4

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"
answered Oct 22, 2015 at 18:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.