0

(NODEJS) Below I have a function that grabs data from a Redis server and returns the result. When I console.log the data in the getKey function it shows the data, however when it returns the data it seems be showing up undefined. I feel like it's something silly but it's been giving me a headache for the last few hours, any insight would be greatly appreciated!

 function getKey(key) {
      client.get(key, function (error, result) {
          if (error) {
              console.log(error);
              throw error;
          } else {
            console.log(JSON.parse(result));
            return JSON.parse(result);
          }
      });
    }

function test() {
  console.log(getKey("abc"));
}
Rand
  • 87
  • 2
  • 9

0 Answers0