-
-
Save maritz/673710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http') | |
, sys = require('sys') | |
, url = require('url') | |
, path = require('path') | |
, fs = require('fs') | |
, net = require('net'); | |
var crlf = "\r\n"; | |
var crlf_len = crlf.length; | |
var mc_server = { | |
ms: '' | |
, buffer: '' | |
, conn: function (port, host, callback) { | |
var self = this; | |
if (!this.ms) { | |
this.ms = new net.createConnection(port, host); | |
this.ms.on('connect', function () { | |
sys.puts('Connected to server: localhost:' + port); | |
callback(self.ms); | |
}); | |
this.ms.on('error', function (exception) { | |
sys.puts('Error: ' + exception); | |
}); | |
this.ms.on('data', function (data) { | |
mc_server.buffer += data; | |
sys.puts(data); | |
}); | |
this.ms.on('end', function () { | |
if (mc_server.ms && mc_server.ms.readyState) { | |
mc_server.ms = null; | |
sys.puts('Disconnected!'); | |
} | |
}); | |
} else { | |
this.ms.on('connect', funtion() { | |
callback(self.ms); | |
} | |
} | |
} | |
, query: function (stmt) { | |
this.conn(11211, 'localhost', function (ms) { | |
//sys.puts(sys.inspect(ms)); | |
ms.write(stmt); | |
}); | |
} | |
}; | |
mc_server.query('get json_foo ' + crlf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment