Skip to content

Commit 431340d

Browse files
committed
updated and tested with node v0.6.15
1 parent dd23a03 commit 431340d

File tree

8 files changed

+152
-415
lines changed

8 files changed

+152
-415
lines changed

examples/get-stress.js

+18-39
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
1-
var Binary = require("binary").Binary;
1+
var Binary = require("../lib/binary").Binary;
22
var memc = require("../lib/parser");
33
var net = require("net");
44

55
process.on('uncaughtException', function (err) {
6-
console.log('Caught exception: ' + JSON.stringify(err, null, "\t"));
6+
console.log('uncaughtException: ' + err);
7+
console.log(err.stack);
78
});
89

910
var key = "stress_test";
10-
11-
var numclients = 10;
12-
var bodysize = 16384;
13-
var encoding = memc.constants.encodings.BINARY;
14-
var quitafter = 1000000;
15-
var chunked = true;
16-
17-
if(process.ARGV.length > 2) {
18-
numclients = process.ARGV[2];
19-
}
20-
if(process.ARGV.length > 3) {
21-
bodysize = process.ARGV[3];
22-
}
23-
if(process.ARGV.length > 4) {
24-
encoding = process.ARGV[4];
25-
}
26-
if(process.ARGV.length > 5) {
27-
quitafter = parseInt(process.ARGV[5]);
28-
}
29-
if(process.ARGV.length > 6) {
30-
chunked = (process.ARGV[6] == "true");
31-
}
11+
var port = process.argv[2] || 11211;
12+
var host = process.argv[3] || "127.0.0.1";
13+
var numclients = process.argv[4] || 10;
14+
var bodysize = process.argv[5] || 16384;
15+
var encoding = process.argv[6] || memc.constants.encodings.ASCII;
16+
var quitafter = process.argv[7] || 1000000;
17+
var chunked = (process.argv[8] === "true");
3218

3319
var data = "";
3420
for(var i=0; i<bodysize; i++) {
@@ -92,27 +78,20 @@ var clients = 0;
9278
var sent = 0;
9379

9480
function writeSocket(socket, buffer) {
95-
if(socket.readyState == "open") {
96-
try {
97-
socket.write(buffer);
98-
bytesout += buffer.length;
99-
sent++;
100-
}
101-
catch(ex) {
102-
103-
}
104-
}
81+
socket.write(buffer);
82+
bytesout += buffer.length;
83+
sent++;
10584
}
10685

10786
function client() {
10887
var connection = new net.Stream();
10988
connection.setNoDelay(true);
11089
connection.setTimeout(0);
11190

112-
connection.ondata = function (buffer, start, end) {
113-
bytesin += (end-start);
114-
connection.parser.execute(buffer, start, end);
115-
};
91+
connection.on("data", function(buffer) {
92+
bytesin += (buffer.length);
93+
connection.parser.execute(buffer, 0, buffer.length);
94+
});
11695

11796
connection.addListener("connect", function() {
11897
clients++;
@@ -165,7 +144,7 @@ function client() {
165144
connection.end();
166145
});
167146

168-
connection.connect("/tmp/memcached.sock");
147+
connection.connect(port, host);
169148
}
170149

171150
for(var i=0; i<numclients; i++) {

examples/test.js

-215
This file was deleted.

examples/testclient.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var sys = require("sys");
21
var memc = require("../lib/client");
32

43
var client = new memc.Connection();
@@ -7,7 +6,10 @@ client.parser.chunked = false;
76
client.parser.encoding = memc.constants.encodings.UTF8;
87

98
var key = "node-memcached-test";
10-
var value = "hello";
9+
var value = "12345";
10+
11+
var port = process.argv[2] || 11211;
12+
var host = process.argv[3] || "127.0.0.1";
1113

1214
/*
1315
{"method": "connect", "params":"port, host, cb"}
@@ -40,59 +42,53 @@ var value = "hello";
4042
{"method": "flushq", "params":"expiration, cb"}
4143
*/
4244

43-
client.connect("/tmp/memcached.sock", null, function() {
44-
sys.puts("connected");
45+
client.connect(port, host, function() {
46+
console.log("connected");
4547
client.flush(null, function(message) {
46-
sys.puts("FLUSH: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
48+
console.log("FLUSH: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
4749
});
4850
client.version(function(message) {
49-
sys.puts("VERSION: " + message.body);
51+
console.log("VERSION: " + message.body);
5052
});
5153
client.noop(function(message) {
52-
sys.puts("NOOP: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
54+
console.log("NOOP: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
5355
});
5456
client.set(key, value, 0x01, 3600, function(message) {
5557
if(message.header.status == memc.constants.status.NO_ERROR) {
56-
sys.puts("SET: OK");
57-
client.getq(key, function(message) {
58-
sys.puts("GETQ: " + message.body);
59-
});
60-
client.getkq(key, function(message) {
61-
sys.puts("GETKQ: " + message.body);
62-
});
63-
client.getk(key, function(message) {
64-
sys.puts("GETK: " + message.body);
65-
});
58+
console.log("SET: OK");
6659
client.get(key, function(message) {
67-
sys.puts("GET: " + message.body);
60+
console.log("GET: " + message.body);
6861
var stat = {};
6962
client.stat(null, function(message) {
7063
if(message.header.bodylen > 0) {
7164
stat[message.key] = message.body;
7265
}
7366
else {
74-
sys.puts("STAT:\n" + JSON.stringify(stat, null, "\t"));
67+
console.log("STAT:\n" + JSON.stringify(stat, null, "\t"));
7568
client.delete(key, function(message) {
76-
sys.puts("DELETE: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
69+
console.log("DELETE: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
7770
client.quit(function(message) {
78-
sys.puts("QUIT: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
71+
console.log("QUIT: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
7972
});
8073
});
8174
}
8275
});
8376
});
8477
}
8578
else {
86-
sys.puts("SET: Error = " + message.header.status);
79+
console.log("SET: Error = " + message.header.status);
80+
client.quit(function(message) {
81+
console.log("QUIT: " + (message.header.status == memc.constants.status.NO_ERROR?"OK":"FAIL"));
82+
});
8783
}
8884
});
8985
});
9086

9187
client.on("error", function(err) {
92-
sys.puts("client error\n" + JSON.stringify(err, null, "\t"));
88+
console.log("client error\n" + JSON.stringify(err, null, "\t"));
9389
});
9490

9591
client.on("close", function() {
96-
sys.puts("client closed");
92+
console.log("client closed");
9793
});
9894

0 commit comments

Comments
 (0)