how to access redis in blocking way instead of non-blocking (event callback) in nodejs

I want to implement Martin Flower's Sequence Generator component in his book Patterns of Enterprise Application Architecture in nodejs with redis as backend.

For example.

var redisClient = ...;
var count = redisClient.get('count');
var stepSize = 1000;
var initCount = 0;
count = count ? count : initCount;
var counterMax = count + stepSize;
redisClient.set('count', counterMax);
var counter = function(){
    ++count;
    if(count>=counterMax){
        counterMax = count + stepSize;
        redisClient.set('count', counterMax);
    }
    return count;
}
module.exports = {
    nextValue: counter
}

In my client, I will use:

var seq = require(./sequence);

app.get('/', function(req, res){
    var token = seq();
    if( req.cookies.userToken ){
        res,cookie( 'userToken', token );
    }

    ....

});

I need to access redis in nodejs in blocking way instead of asynchronous way, Is there a way to go? and How?

I need to access redis in nodejs in blocking way instead of asynchronous way

I don't know if there is a redis library with sync API, but bear in mind it would probably introduce potential bottleneck for your entire application since you will block it until your sync operation is done which is against the idioms on node.js.

Is there a way to go? and How?

You can either try to execute a "logicless" set of commands through transaction or since redis version 2.6 it's possible to execute lua scripts directly on redis side that might be a way to go for you. Not only will you offload some operations from your node.js application saving multiple roundtrips, but the script will be executed atomically in redis and you won't have to deal with managing of several callbacks in your application.