7

Can you save nested objects in redis?

I'm using the node.js driver. One of my key-values is an array of objects. If I dont stringify it results in the string "[object Object]" if i stringify it I get this error:

{ 
stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'ERR wrong number of arguments for \'hmset\' command' 
}

2 Answers 2

2

stringifying json is not the right way of using redis. you should generate your own redis hashsets

user:ejder name ejder user:ejder:details:0 age 32 user:ejder:details:1 age 25 (i wish)

that way you can query your data redis-way. Stringifying json is nothing but saving a string and if you use large datasets it will decrease the performance very bad

Sign up to request clarification or add additional context in comments.

3 Comments

Redis should have better support for json/js objects.
it's made to be fast and has a single thread architecute. so supporting nested objects is not an easy job for redis.
@boom - perhaps you have selected the wrong tool. If you want easy storage of JSON I'd recommend taking a look at mongodb.
1

Stringifying simple object to it's JSON representations should work and it seems that you have some syntax error in your code (can you please update your question with corresponding code where you are doing the HMSET command?). If you are not ok with stringified version, then each of your object in array should have dedicated hash structure where their data would be located.

Alternatively you can try to use node.js implementation of a object-hash mapping library for redis.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.