-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
100 lines (92 loc) · 2.1 KB
/
client.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var express = require('express');
var Sessionify = require('./index.js');
var clientObj = Sessionify.Client(express, {
secret: 'gica123',
servers: [{
host: '127.0.0.1',
port: 18555
}]
});
clientObj.on('error', function(err) {
console.log("ERROR", err);
}).on('warn', function(msg) {
console.log('WARN', msg);
})
console.log("Testing...");
clientObj.on('ready', function() {
var MAX_SESSIONS = 10,
FAILS = 0,
CURRENT = 0,
TIMES = [],
STARTED = new Date().getTime();
return;
var sendSession = function() {
var sid = new Date().getTime().toString() + Math.random().toString(),
data = {
onestring: "eqw" + new Date().getTime(),
gica: "Math."
};
var now = new Date().getTime();
clientObj.set(sid, data, function(wasOk) {
if(!wasOk) FAILS++;
CURRENT++;
var took = new Date().getTime() - now;
TIMES.push(took);
if(CURRENT < MAX_SESSIONS) {
sendSession();
} else {
onFinish();
}
});
};
var onFinish = function() {
console.log("Test took: " + (new Date().getTime() - STARTED) + "ms.");
console.log("SET Requests: " + MAX_SESSIONS);
var avg = 0;
for(var i=0; i < TIMES.length; i++) {
avg += TIMES[i];
}
avg = Math.round(avg/TIMES.length);
console.log("Average time: " + avg + "ms");
clearTimeout(a);
};
sendSession();
var a = setInterval(function() {
console.log('Sent ' + CURRENT);
}, 1000);
});
var app = express();
app.use(express.errorHandler());
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser("secret123"));
app.use(express.session({
key: 'sid',
secret: 'secret123',
cookie: {
secure: false,
maxAge: 24 * 60 * 60 * 1000
//domain:
},
store: clientObj
}));
app.use(app.router);
app.get('/', function(req, res) {
console.log("CONECTED:", req.session.name);
req.session.name = "MATA";
res.write("HI");
console.log(req.session);
res.end();
});
app.get('/update', function(req, res) {
req.session.nume = Math.random();
res.write("HO");
res.end();
});
app.get('/1', function(req, res) {
req.session.destroy();
res.write("DONE");
res.end();
});
app.listen(3128);