Permalink
Browse files

events emitted with passed arguments and returned value

  • Loading branch information...
1 parent d8ec7dc commit 2f27f78f1d27e17fadbcfb5e131f9c3b71543218 @fent fent committed Feb 18, 2012
Showing with 133 additions and 69 deletions.
  1. +34 −28 lib/eventvat.js
  2. +99 −41 test/events-test.js
View
@@ -137,7 +137,7 @@
}
}
- this.emit('keys', keys, regex);
+ this.emit('keys', regex, keys);
return keys;
};
@@ -289,9 +289,10 @@
}
var newValue = this.hash[key].value += value;
- this.emit('append ' + key, value, newValue);
- this.emit('append', key, value, newValue);
- return newValue.length;
+ var len = newValue.length;
+ this.emit('append ' + key, value, len);
+ this.emit('append', key, value, len);
+ return len;
};
//
@@ -354,8 +355,8 @@
EventVat.prototype.getrange = function(key, start, end) {
if (this.type(key) === 'string') {
var value = this.hash[key].value.slice(start, end);
- this.emit('getrange ' + key, value);
- this.emit('getrange', key, value);
+ this.emit('getrange ' + key, start, end, value);
+ this.emit('getrange', key, start, end, value);
return value;
} else {
return false;
@@ -408,11 +409,16 @@
// Get the values of all the given keys
//
EventVat.prototype.mget = function(key /* ... */) {
+ var keys = Array.prototype.slice.call(arguments);
var values = [];
- for(var i=0, l=arguments.length; i < l; i++) {
- values.push(this.get(arguments[i]));
+
+ for(var i=0, l=keys.length; i < l; i++) {
+ values.push(this.get(keys[i]));
}
- this.emit('mget', values);
+
+ keys.unshift('mget');
+ keys.push(values);
+ this.emit.apply(this, keys);
return values;
};
@@ -550,8 +556,8 @@
this.persist(key);
this.hash.value = newValue;
- this.emit('setrange ' + key, newValue);
- this.emit('setrange', key, newValue);
+ this.emit('setrange ' + key, offset, value, l);
+ this.emit('setrange', key, offset, value, l);
return l;
} else {
return false;
@@ -815,8 +821,8 @@
}
this.hash[key].value[field] = value;
- this.emit('hset ' + key, field, value);
- this.emit('hset', key, field, value);
+ this.emit('hset ' + key, field, value, update);
+ this.emit('hset', key, field, value, update);
return update;
};
@@ -948,12 +954,12 @@
for (var i = 1, l = arguments.length; i < l; i++) {
var val = arguments[i];
- list.unshift(val);
- this.emit('lpush ' + key, val);
- this.emit('lpush', key, val);
+ var len = list.unshift(val);
+ this.emit('lpush ' + key, val, len);
+ this.emit('lpush', key, val, len);
}
- return list.length;
+ return len;
};
//
@@ -962,8 +968,8 @@
EventVat.prototype.lpushx = function(key, value) {
if (this.type(key) === 'list') {
var len = this.hash[key].value.unshift(value);
- this.emit('lpushx ' + key, value);
- this.emit('lpushx', key, value);
+ this.emit('lpushx ' + key, value, len);
+ this.emit('lpushx', key, value, len);
return len;
} else {
return 0;
@@ -1107,13 +1113,13 @@
this.persist(source);
var value = this.hash[source].value.pop();
- dest.unshift(value);
+ var len = dest.unshift(value);
this.emit('rpoplpush ' + source, destination, value);
this.emit('rpoplpush', source, destination, value);
this.emit('rpop ' + source, value);
this.emit('rpop', source, value);
- this.emit('lpush ' + destination, value);
- this.emit('lpush', destination, value);
+ this.emit('lpush ' + destination, value, len);
+ this.emit('lpush', destination, value, len);
return value;
} else {
return null;
@@ -1138,12 +1144,12 @@
for (var i = 1, l = arguments.length; i < l; i++) {
var val = arguments[i];
- list.push(val);
- this.emit('rpush ' + key, val);
- this.emit('rpush', key, val);
+ var len = list.push(val);
+ this.emit('rpush ' + key, val, len);
+ this.emit('rpush', key, val, len);
}
- return list.length;
+ return len;
};
//
@@ -1152,8 +1158,8 @@
EventVat.prototype.rpushx = function(key, value) {
if (this.type(key) === 'list') {
var len = this.hash[key].value.push(value);
- this.emit('rpushx ' + key, value);
- this.emit('rpushx', key, value);
+ this.emit('rpushx ' + key, value, len);
+ this.emit('rpushx', key, value, len);
return len;
} else {
return 0;
Oops, something went wrong.

0 comments on commit 2f27f78

Please sign in to comment.