Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14 from dscape/master

[getdel] Adds getdel
  • Loading branch information...
commit afdc7a55cb091778d9828df11fdfaec67e5b21b7 2 parents 79c9dec + 74a0742
Paolo Fragomeni authored
Showing with 33 additions and 28 deletions.
  1. +33 −28 lib/eventvat.js
View
61 lib/eventvat.js
@@ -21,7 +21,7 @@
//
function has(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
- };
+ }
EventVat = module.exports = function EventVat(conf) {
@@ -43,10 +43,10 @@
p.unsubscribe = EventEmitter2.prototype.removeListener;
p.die = function(key) {
- for (var key in this.hash) {
- if (has(this.hash, key)) {
- if (this.hash[key].tid) {
- clearTimeout(this.hash[key].tid);
+ for (var k in this.hash) {
+ if (has(this.hash, k)) {
+ if (this.hash[k].tid) {
+ clearTimeout(this.hash[k].tid);
}
}
}
@@ -156,7 +156,7 @@
return true;
}
return false;
- }
+ };
//
// Inspect the internals of EventVat objects
@@ -330,32 +330,37 @@
//
p.get = function(key) {
- var newValue;
+ var newValue = null;
if(has(this.hash, key)) {
- var newValue = this.hash[key].value;
+ newValue = this.hash[key].value;
this.emit('get ' + key, newValue);
this.emit('get', key, newValue);
- return newValue;
- }
- else {
- return null;
}
+
+ return newValue;
+
+ };
+
+ p.getDel = function (key) {
+ var newValue = p.get(key);
+ p.del(key);
+ this.emit('getdel ' + key, newValue);
+ this.emit('getdel', key, newValue);
};
p.gettime = function() {
- var newValue;
+ var newValue = null;
if(has(this.hash, key)) {
- var newValue = this.hash[key].time;
+ newValue = this.hash[key].time;
this.emit('gettime ' + key, newValue);
this.emit('gettime', key, newValue);
- return newValue;
- }
- else {
- return null;
}
+
+ return newValue;
+
};
//
@@ -451,7 +456,7 @@
}
// set events must be emitted after keys are updated
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
@@ -459,7 +464,7 @@
this.emit('set', key, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
args.unshift('mset');
this.emit.apply(this, args);
return true;
@@ -477,7 +482,7 @@
}
}
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
@@ -486,7 +491,7 @@
}
}
- for(var i=0, l=arguments.length; i < l; i += 2) {
+ for(i=0, l=arguments.length; i < l; i += 2) {
key = arguments[i];
value = arguments[i + 1];
@@ -496,7 +501,7 @@
this.emit('setnx', key, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
args.unshift('msetnx');
this.emit.apply(this, args);
return true;
@@ -801,7 +806,7 @@
// set events must be emitted after keys are updated
var field, value;
- for(var i=1, l=arguments.length; i < l; i += 2) {
+ for(i=1, l=arguments.length; i < l; i += 2) {
field = arguments[i];
value = arguments[i + 1];
@@ -809,7 +814,7 @@
this.emit('hset', key, field, value);
}
- var args = Array.prototype.slice.call(arguments)
+ var args = Array.prototype.slice.call(arguments);
this.emit.apply(this, ['hmset ' + key].concat(args.slice(1)));
this.emit.apply(this, ['hmset'].concat(args));
return true;
@@ -992,7 +997,7 @@
//
p.lrange = function(key, start, stop) {
var range = this.type(key) === 'list'
- ? this.hash[key].value.slice(start, stop) : []
+ ? this.hash[key].value.slice(start, stop) : [];
this.emit('lrange ' + key, start, stop, range);
this.emit('lrange', key, start, stop, range);
@@ -1012,7 +1017,7 @@
// if count is positive, list will be traversed from 0 to list.length
if (ncount >= 0) {
i = 0;
- check = function() { return i < list.length };
+ check = function() { return i < list.lengthl; };
incr = function() { i++; };
cancel = function() { i--; };
@@ -1232,7 +1237,7 @@
//
p.findin = function(key, value) {
if(has(this.hash, key)) {
- var index = this.hash[key].value.indexOf(value)
+ var index = this.hash[key].value.indexOf(value);
this.emit('findin ' + key, value, index);
this.emit('findin', key, value, index);
return index;

0 comments on commit afdc7a5

Please sign in to comment.
Something went wrong with that request. Please try again.