Hi community!!
I’m in troubles with redis ( i’m new with redis ) and how to get keys because the async nature of node_redis ( I think ).
I’m trying to:
- query a mongodb DB and set a list of keys with data => done
- set expiry to every key => done
- pub/sub and get a message when a key expires =>
- when receive the message of the expired key, set it agains => ERROR
The poblem is that I always get a null or undefinied value. Here is my test code:
pubsub.on('psubscribe', function() {
while(i<end){
client.set( i , data, function() {
});
client.expire( i , 10);
console.log("New key added: " + i);
i++;
}
});
And then when expires:
pubsub.on('pmessage', function(data, channel, message) {
console.log("Key expired: " + message);
client.get(message,(err,data)=>{
client.set( message , data,()=>{
client.expire( message , 10);
});
});
});
The last code returns error because data is null or undefined.
How can I solve it??
Thanks a lot!