lib/client.js
function makeBeanstalkCommand(command, expectedResponse, sendsData)
{
	// Commands are called as client.COMMAND(arg1, arg2, ... data, callback);
	// They're sent to beanstalkd as: COMMAND arg1 arg2 ...
	// followed by data.
	// So we slice the callback & data from the passed-in arguments, prepend
	// the command, then send the arglist otherwise intact.
	// We then push a handler for the expected response onto our handler stack.
	// Some commands have no args, just a callback (stats, stats-tube, etc);
	// That's the case handled when args < 2.
	return function()
	{
		var data,
			buffer,
			args = argHashToArray(arguments),
			callback = args.pop();

		args.unshift(command);

		if (sendsData)
		{
			data = args.pop();
			if (!Buffer.isBuffer(data))
				data = new Buffer(data);
			args.push(data.length);
		}

		this.handlers.push([new ResponseHandler(expectedResponse), callback]);

		if (data)
		{
			buffer = Buffer.concat([new Buffer(args.join(' ')), CRLF, data, CRLF]);
		}
		else
		{
			buffer = Buffer.concat([new Buffer(args.join(' ')), CRLF]);
		}
		this.stream.write(buffer);
	};
}
function makeBeanstalkCommand(command, expectedResponse, sendsData)
{
	// Commands are called as client.COMMAND(arg1, arg2, ... data, callback);
	// They're sent to beanstalkd as: COMMAND arg1 arg2 ...
	// followed by data.
	// So we slice the callback & data from the passed-in arguments, prepend
	// the command, then send the arglist otherwise intact.
	// We then push a handler for the expected response onto our handler stack.
	// Some commands have no args, just a callback (stats, stats-tube, etc);
	// That's the case handled when args < 2.
	return function()
	{
		var data,
			buffer,
			args = argHashToArray(arguments),
			callback = args.pop();

		args.unshift(command);

		if (sendsData)
		{
			data = args.pop();
			if (!Buffer.isBuffer(data))
				data = new Buffer(data);
			args.push(data.length);
		}

		this.handlers.push([new ResponseHandler(expectedResponse), callback]);

		if (data)
		{
			buffer = Buffer.concat([new Buffer(args.join(' ')), CRLF, data, CRLF]);
		}
		else
		{
			buffer = Buffer.concat([new Buffer(args.join(' ')), CRLF]);
		}
		this.stream.write(buffer);
	};
}
function makeBeanstalkCommand ( command , expectedResponse , sendsData ) { // Commands are called as client.COMMAND(arg1, arg2, ... data, callback); // They're sent to beanstalkd as: COMMAND arg1 arg2 ... // followed by data. // So we slice the callback & data from the passed-in arguments, prepend // the command, then send the arglist otherwise intact. // We then push a handler for the expected response onto our handler stack. // Some commands have no args, just a callback (stats, stats-tube, etc); // That's the case handled when args < 2. return function ( ) { var data , buffer , args = argHashToArray ( arguments ) , callback = args . pop ( ) ; args . unshift ( command ) ; if ( sendsData ) { data = args . pop ( ) ; if ( ! Buffer . isBuffer ( data ) ) data = new Buffer ( data ) ; args . push ( data . length ) ; } this . handlers . push ( [ new ResponseHandler ( expectedResponse ) , callback ] ) ; if ( data ) { buffer = Buffer . concat ( [ new Buffer ( args . join ( ' ' ) ) , CRLF , data , CRLF ] ) ; } else { buffer = Buffer . concat ( [ new Buffer ( args . join ( ' ' ) ) , CRLF ] ) ; } this . stream . write ( buffer ) ; } ; }
Implementing the beanstalkd interface.
Implementing the beanstalkd interface .