0

I am writing a NodeJS app that does a get request to a third party api. This api returns a list of dictionaries. I would like to take this result, and store it in my redis client. How do I do that?

The results object looks like this -

[{"foo":123, "bar":456}, {"foo":789, "bar":012}]
2
  • It's difficult to give much of an answer without knowing how to would like to retrieve the data out of redis, because that will dictate how you enter it into redis. How would you like to retrieve the data? Commented Apr 23, 2018 at 23:00
  • @generalhenry So once redis has the above list of dictionaries into Redis, I would do a lpop mylist to get the values. This will return an element of type dictionary. Commented Apr 24, 2018 at 0:30

2 Answers 2

1

It sounds like you don't need to query elements from the dicts so it should be fine just storing them as json strings in a redis list. When you bulk add to the list you can stringify them, just make sure to use some form of pipe-lining so you're not making unneeded api calls. Then you can simply parse the json string dicts when you need them. ex:

function setList (list, callback) {
  const pipeline = redis.pipeline();
  for (const dict of list) {
    pipeline.rpush('myList', JSON.stringify(dict));
  }
  pipeline.exec(callback);
}

function popList (callback) {
  redis.lpop('mylist', function (error, data) {
    if (error) { return callback(error) }
    callback(null, JSON.parse(data));
  });
}
Sign up to request clarification or add additional context in comments.

Comments

0

I would do it simple assuming your data as list or list as string,

      let redis = require("redis"),
      publisher = redis.createClient(option.redisPort, option.redisHost); 
      publisher.publish("id", DATA);  // here we publish the data. 

Are you looking for something like this?

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.