Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[getdel] Adds getdel #14

Merged
merged 2 commits into from Mar 16, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 33 additions & 28 deletions lib/eventvat.js
Expand Up @@ -21,7 +21,7 @@
//
function has(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
};
}

EventVat = module.exports = function EventVat(conf) {

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@
return true;
}
return false;
}
};

//
// Inspect the internals of EventVat objects
Expand Down Expand Up @@ -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;

};

//
Expand Down Expand Up @@ -451,15 +456,15 @@
}

// 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];

this.emit('set ' + key, value);
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;
Expand All @@ -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];

Expand All @@ -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];

Expand All @@ -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;
Expand Down Expand Up @@ -801,15 +806,15 @@

// 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];

this.emit('hset ' + key, field, value);
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;
Expand Down Expand Up @@ -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);
Expand All @@ -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--; };

Expand Down Expand Up @@ -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;
Expand Down