Reputation: 8279
If I want to display the recent X amount of recent posts\comments on the page, I store a list of IDs using LPUSH
and then use LTRIM
to keep the list a certain size.
Do I then use the IDs returned from LRANGE
to get the details of the post\comments from:
a) Redis using MGET
where I pass:
MGET comment.1.author, comment.1.content, comment.1.timestamp, comment.2.author, etc
Is it OK to store all the comments details in Redis like that?
b) SQL Database using the list if IDs in a query
Upvotes: 3
Views: 387
Reputation: 1063088
If you want to store the fields individually like that, a hash would seem more appropriate than 5 keys each, i.e. where "comment.1" is the key, with subkeys "author", "content", etc. However, unless you have a reason to just want the IDs, I would be tempted to store the entire thing as a serialized chunk of json or binary - then you just LRANGE
and you have the data - no fuss, and minimal trips.
To reduce bandwidth, I'd use something like protobuf-net for the storage (although I may be biased), and if you need a binary safe client BookSleeve will do quite nicely.
Upvotes: 3