Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How should I store JSON in redis?

How should I store JSON in redis?

Problem

I have Json (node.js. What are the pros and cons of storing it as an object or string? Are there other options I missed? All processing will ultimately happen on the client side, so converting into an object is not necessary.

SET

var images = JSON.parse(data);          // data is already JSON, is this needed?
callback(images);                       // sends result to the user
r.set('images:' + req.query, images);   // saving the object

GET

callback(images);
Problem courtesy of: tofutim

Solution

You can Store Json in redis either as a plain string in dedicated key (or member/value of a set/list) or in a hash structure. If you look at node_redis docs into Friendlier hash commands part you'll see that it gives you some useful methods for manipulating JSON based data. Pros of this approach is that it allows you to get/set only part of the original object and it might also consume less memory compared to plain strings.

Solution courtesy of: yojimbo87

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How should I store JSON in redis?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×