Categories
JavaScript Answers

How to store objects in Node.js redis?

Spread the love

To store objects in Node.js redism we call the hmset method.

For instance, we write

client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");

client.hgetall("hosts", (err, obj) => {
  console.dir(obj);
});

to call hmset with the key 'hosts' and the subsequent arguments as key-value pairs.

Then we get the value with with key 'hosts' with hgetall.

We get the value from obj in the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *