I can store a key/value in Redis but I can't retrieve the value.
store.js
var client = redis.createClient();
token ='ghg782Nm';
webhook = 'http://test.com';
//store the key/value in Redis
client.set(token, webhook, function(err, reply) {
if (err) {
console.log(err);
}
});
//get the value
client.get(token, function(err, value) {
if (err) {
console.log(err);
}
console.log(value); //return 'http://test.com'
});
I get the right value here but when I want to get it from a different file (somewhere_else.js), the value is null.
somewhere_else.js
var client = redis.createClient();
token ='ghg782Nm';
//get the value
client.get(token, function(err, value) {
if (err) {
console.log(err);
}
console.log(value); //Return null
});
What did I miss? Thanks a lot!
clientinstance between the two files? Perhaps theset()hasn't finished before you callget()from the other file?store.jsandsomewhere_else.js, and use it for both the operations. But make sure you're callinggetonly aftersetis finished.