app.get('/tools/export', function (req, res) {
    var urlParams = url.parse(req.url, true).query,
        connection = urlParams.connection.split(':'),
        connectionId = 0;

    if (!connection[0]) {
      connection = ['localhost', '6379', '0'];
    }

    for (var i in req.redisConnections) {
      if (!req.redisConnections[i].options) {
        continue;
      }
      if (req.redisConnections[ i ].options.host === connection[0] && req.redisConnections[ i ].options.port === connection[1] &&
        req.redisConnections[ i ].options.db === connection[2]) {
        connectionId = i;
        break;
      }
    }

    var dump = new RedisDump({
      client: req.redisConnections[ connectionId ]
    });

    dump.export({
      type: urlParams.type || 'redis',
      callback: function(err, data) {
        if (err) {
          console.error('Could\'t not make redis dump!', err);
          return;
        }

        res.setHeader('Content-disposition', 'attachment; filename=db.' + (new Date().getTime()) + '.redis');
        res.setHeader('Content-Type', 'application/octet-stream');

        switch (urlParams.type) {
          case 'json':
            res.end(JSON.stringify(data));
            break;

          default:
            res.end(data);
            break;
        }
      }
    });
  });
Exemple #2
0
        host: '10.254.53.247',
        port: 6486,
        password: ''
    });

dump.connect();
dump.export({
    type: 'redis',
    //isCompress: false, (not working now)
    callback: function(err, data) {
        if (err) {
            console.log('Could\'t not make redis dump!', err);
            return;
        }

        console.log('--------- REDIS DUMP ----------');
        //console.log(data);

        var fs = require('fs');
        var path = "/home/trieunt/data/redis-247-6486-dump.txt";
        fs.writeFile(path, data, function(err) {
            if(err) {
                console.log(err);
            } else {
                console.log("The data was saved at "+path);
            }
        });

        console.log('--------- /REDIS DUMP ----------');
    }
});