using the result from a databse request in node.js

I am not sure what the callback function should look like if I want to do this. Both functions are in a class and I really want to abstract it.

doesexist: function(setvalue) {
  redisclient.sismember('setname', setvaue, callbackfuntion(value));
}

someothermethod: function() {
  if (doesexist()){
    // doSomething
  }
}

How would I do that in an async environment?

UPDATE:

I now tried it that way (coffeescript):

deoesexist: (setvalue, cb) ->
  @r.sismember 'setname', setvalue, (err, res) -> cb(res)

someothermethod: (setvalue) ->
  @doesexist setvalue, (exists) =>
    unless exists
      # emit an event that calls a function
      # that probably adds the not existing value.
      # I just don't want to redo this. That's
      # what this function is all about

It seems to work pretty well like that.

You should checkout out control flow libraries, https://npmjs.org/browse/keyword/flow, to determine which approach is best for you, I prefer the async library https://github.com/caolan/async

To answer your question you would work your problem in the following way;

doesexist: function(setvalue, callback) {
    redisclient.sismember('setname', setvaue, callback);
}

someothermethod: function(somevalue) {
   doesexist(somevalue, function(err, exists) {
         if (exists) {
            // doSomething
         }
   })
}

I hope that helps!

Jay

I figured it out. One basically replaces the if statement with the callback function. Simple, if you think more high level about what you are actually doing, but hard when you are just not used to it.

See my update for the answer.