Example #1
0
 setUp: function(next) {
   if (!nohm.client) {
     nohm.setClient(redis);
   }
   var t = this;
   
   if ( ! users_created) {
     createUsers([{
       name: 'metatestsone',
       email: '*****@*****.**',
       gender: 'male',
       number: 3
     }, {
       name: 'metateststwo',
       email: '*****@*****.**',
       gender: 'male',
       number: 4
     }], function(users, ids) {
       var comment = nohm.factory('CommentMetaMockup');
       users_created = true;
       users[0].link(comment);
       users[0].save(function () {
         t.users = users;
         t.userIds = ids;
         next();
       });
     });
   } else {
     next();
   }
 },
Example #2
0
exports.setRedisClient = function (t) {
  t.expect(2);
  console.log('Note: there should be an error message in the next line. (intended behaviour)');
  var user = new UserMockup();
  t.same(user, {}, 'Creating a model without having a nohm client set did not return false.');
  
  nohm.setClient(redis);
  user = new UserMockup();
  t.equals(typeof(user.modelName), 'string', 'Creating a model having a nohm client set did not work.');
  t.done();
};
Example #3
0
 setUp: function(next) {
   if (!nohm.client) {
     nohm.setClient(redis);
   }
   var t = this;
   h.cleanUp(redis, args.prefix, function() {
     createUsers([{
       name: 'numericindextest',
       email: '*****@*****.**',
       gender: 'male',
       number: 3
     }, {
       name: 'numericindextest',
       email: '*****@*****.**',
       gender: 'male',
       number: 4,
       number2: 33
     }, {
       name: 'numericindextest',
       email: '*****@*****.**',
       gender: 'female',
       number: 4,
       number2: 1
     }, {
       name: 'uniquefind',
       email: '*****@*****.**'
     }, {
       name: 'indextest',
       email: '*****@*****.**'
     }, {
       name: 'indextest',
       email: '*****@*****.**'
     }, {
       name: 'a_sort_first',
       email: '*****@*****.**',
       number: 1
     }, {
       name: 'z_sort_last',
       email: '*****@*****.**',
       number: 100000
     }], function(users, ids) {
       t.users = users;
       t.userIds = ids;
       next();
     });
   });
 },
Example #4
0
 setUp: function (next) {
   if ( ! nohm.client) {
     nohm.setClient(redis);
   }
   next();
 },
Example #5
0
var express = require('express');
var Nohm = require(__dirname+'/../../lib/nohm.js').Nohm;
var UserModel = require(__dirname+'/UserModel.js');
var redis = require('redis');
var fs = require('fs');

var redisClient = redis.createClient();

Nohm.setPrefix('rest-user-server-example');
Nohm.setClient(redisClient);

var server = express.createServer();

server.use(express.bodyParser());

server.get('/User/list', function (req, res, next) {
  UserModel.find(function (err, ids) {
    if (err) {
     return next(err);
    }
    var users = [];
    var len = ids.length;
    var count = 0;
    if (len === 0) {
      return res.json(users);
    }
    ids.forEach(function (id) {
      var user = new UserModel();
      user.load(id, function (err, props) {
        if (err) {
          return next(err);
Example #6
0
File: child.js Project: CowLeo/nohm
args.redis.on('ready', function () {
  nohm.setClient(args.redis);
});
Example #7
0
var nohm        = require(__dirname+'/../lib/nohm').Nohm,
    iterations = 1, // Around 10k total model inserts.
    user;
    
nohm.setPrefix('stress');
nohm.setClient(require('redis').createClient());

var models = require(__dirname+'/models');
var UserModel    = models.user;

var counter = 0;
var start = + new Date();
var users = [];

var callback = function (err) {
  if (err) {
    console.log('update error: ' + err);
    process.exit();
  }
  counter++;
  if (counter >= iterations) {
    console.log((+ new Date()) - start+' ms for '+counter+' User saves and an equal amount of updates.');
    console.log('done');
    process.exit();
  }
};

var update = function update () {
  counter = 0;
  for (var i = 0, len = users.length; i < len; i++) {
    users[i].save(callback);
Example #8
0
var redis = require('redis');
var nohm = require(__dirname+'/../../lib/nohm').Nohm;
var args = require(__dirname+'/../testArgs.js');

nohm.setPrefix(args.prefix);
nohm.setClient(args.setClient);
require(__dirname+'/Model.js');

process.on('message', function (msg) {
  var event, modelName, fn;
  
  switch (msg.question) {
    case 'does nohm have pubsub?':
      process.send({
        question: msg.question,
        answer: nohm.getPubSubClient()
      });
    break;
    
    case 'initialize':
      nohm.setPubSubClient(redis.createClient(args.redis_port, args.redis_host), function (err) {
        process.send({
          question: msg.question,
          answer: err || true,
          error: err
        });
      });
    break;
    
    case 'subscribe':
      event = msg.args.event;