-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
45 lines (35 loc) · 840 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var async = require('async');
var spawn = require('child_process').spawn;
var redisPipe = spawn('redis-cli', ['--pipe']);
redisPipe.stdout.setEncoding('utf8');
redisPipe.stdout.pipe(process.stdout);
redisPipe.stderr.pipe(process.stderr);
var buf = '';
var start = Date.now();
async.times(1000000, function(n, cb) {
if (n % 10000 === 0) {
console.log(n, '@', (n / (Date.now() - start)) * 1000, 'cmds/s');
}
var cmd = 'SET';
var key = 'testo:' + n;
var value = n + '';
var out = [
'*3'
, '$' + cmd.length
, cmd
, '$' + key.length
, key
, '$' + value.length
, value
];
var msg = out.join('\r\n') + '\r\n';
buf += msg;
if (buf.length > (1 << 19)) {
redisPipe.stdin.write(buf);
buf = '';
}
cb();
}, function() {
redisPipe.stdin.write(buf);
redisPipe.stdin.end();
});