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

redis node library json serialization for list values

redis node library json serialization for list values

Problem

I'm trying to create an activity feed list in redis using the redis-node library and had a json serialization question.

If I lpush a value into a key, the values get stored as escaped json, and when I retrieve with lrange, I get a list of escaped json back.

Should I simply iterate over the list items and JSON.parse(item) each, or is there a better more efficient method? Specifically, is there a configuration I can use to avoid the overhead of escaping and unescaping the json values?

Problem courtesy of: MonkeyBonkey

Solution

Use JSON.strinfigy(object) when storing your value and use JSON.parse(value) when retrieving it.

Solution courtesy of: fent

Discussion

View additional discussion.



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

Share the post

redis node library json serialization for list values

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×