summaryrefslogtreecommitdiffhomepage
path: root/benchmarks/workloads/node_template/index.js
blob: 04a27f3560a51641f4701a47b1b71444aa824d9b (plain)
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
const app = require('express')();
const path = require('path');
const redis = require('redis');
const srs = require('secure-random-string');

// The hostname is the first argument.
const host_name = process.argv[2];

var client = redis.createClient({host: host_name, detect_buffers: true});

app.set('views', __dirname);
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
  var tmp = [];
  /* Pull four random keys from the redis server. */
  for (i = 0; i < 4; i++) {
    client.get(Math.floor(Math.random() * (100)), function(err, reply) {
      tmp.push(reply.toString());
    });
  }

  res.render('index', {text: tmp});
});

/**
 * Securely generate a random string.
 * @param {number} len
 * @return {string}
 */
function randomBody(len) {
  return srs({alphanumeric: true, length: len});
}

/** Mutates one hundred keys randomly. */
function generateText() {
  for (i = 0; i < 100; i++) {
    client.set(i, randomBody(1024));
  }
}

generateText();
app.listen(8080);