开发者

Should I only store IDs into Redis and then query SQL using the IDs

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 commen开发者_如何学Gots details in Redis like that?

b) SQL Database using the list if IDs in a query


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜