Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I store JSON in redis?

Tags:

node.js

redis

I have JSON (<1k) to store in Redis through 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); 
like image 438
tofutim Avatar asked Jan 24 '12 12:01

tofutim


People also ask

What is the best way to store JSON?

JSON storage format LOB storage - JSON documents can be stored as-is in NVARCHAR columns. This is the best way for quick data load and ingestion because the loading speed is matching loading of string columns.

Does Redis return JSON?

RedisJSON lets you store, update, and retrieve JSON values in a Redis database, similar to any other Redis data type. RedisJSON also works seamlessly with RediSearch to let you index and query JSON documents.

What is Redis JSON?

RedisJSON is a high-performance NoSQL document store that allows developers to build modern applications. It provides native APIs to ingest, index, query, and run full-text search on JSON documents both on-premises and as a managed service in the cloud. Download.

Is it good practice to store JSON in database?

JSON is perfect for storing temporary data that's consumed by the entity that creates the data. A good example is user-generated data such as filling out a form or information exchange between an API and an app.


1 Answers

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.

like image 184
yojimbo87 Avatar answered Sep 30 '22 11:09

yojimbo87