Node.js and Redis problem

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!

then there should be something in err giving you a clue.

Ups sorry!, I wanted to say that it returns “null”. No error message returned in any case.
Because data = null when I get de key/data, client.set prints:
node_redis: Deprecated: The SET command contains a “null” argument.

Thanks!

then this means that your key doesn’t have a match (=> client.get()) in Redis. which you explicitly have to test.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.