Can you save nested objects in redis?

Is it possible to save nested objects in redis?

I am using the node.js. driver One of my key values ​​is an array of objects. If I am not strict, this will result in the string "[Object Object]", if I build it, I get this error:

{ stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'ERR wrong number of arguments for \'hmset\' command' } 
+6
source share
2 answers

stringifying json is the wrong way to use redis. you have to create your own redis hashsets

user: ejder name ejder user: ejder: details: 0 age 32 user: ejder: details: 1 age 25 (I want)

so you can request your redis-way request. A json string is nothing more than saving a string, and if you use large datasets, this will greatly degrade performance.

+3
source

Strict simple object for it JSON representations should work, and it seems that you have a syntax error in your code (can you please update your question with the appropriate code, where do you execute the HMSET command?). If you are not okay with the string version, then each of your object in the array must have a dedicated hash structure where the data will be located.

Alternatively, you can try using the node.js implementation of the object-hash mapping library for redis.

+1
source

Source: https://habr.com/ru/post/898177/


All Articles