0

I am using node.js to store a simple unduplicated list to redis and retrive it.

However, when I trying to check the result like this, the console will not log anything

client.sAdd('frameworks_set',['ReactJS', 'Angular', 'Svelte', 'VueJS', 'VueJS'],function(err, reply){
    console.log("retieved"+ reply)});

client.sMembers('frameworks_set',function(err, reply){
    console.log("retieved"+ reply)
});

I can see that my list has been added to redis successfully but not sure how would I retrieve the list back to node.js now

127.0.0.1:6379> smembers frameworks_set
1) "Angular"
2) "Svelte"
3) "VueJS"
4) "ReactJS"

1 Answer 1

1

either await the promise or use .then

// using `await`
await client.sAdd('frameworks_set',['ReactJS', 'Angular', 'Svelte', 'VueJS', 'VueJS']);
const reply = await client.sMembers('frameworks_set');

// using `.then`
client.sAdd('frameworks_set',['ReactJS', 'Angular', 'Svelte', 'VueJS', 'VueJS']).then(() => {
  return client.sMembers('frameworks_set');
}).then(reply => {
  // ...
});

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

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

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.