Permalink
Browse files

added missing `persist` calls when keys are updated

  • Loading branch information...
fent committed Feb 7, 2012
1 parent 49516cd commit 1b7a3aef03626f3d8c017eda554cfd083d02d51d
Showing with 24 additions and 1 deletion.
  1. +24 −1 lib/eventvat.js
View
@@ -62,6 +62,7 @@
for (var i = 0, l = arguments.length; i < l; i++) {
key = arguments[i];
if(has(this.hash, key)) {
+ this.persist(key);
delete this.hash[key];
this.emit('del ' + key);
this.emit('del', key);
@@ -196,6 +197,7 @@
EventVat.prototype.rename = function(oldKey, newKey) {
if(has(this.hash, oldKey)) {
this.persist(oldKey);
+ this.persist(newKey);
this.hash[newKey] = this.hash[oldKey];
delete this.hash[oldKey];
this.emit('rename ' + oldKey, newKey);
@@ -574,6 +576,8 @@
var n = 0;
if (this.type(key) === 'hash') {
+ this.persist(key);
+
for (var i=1, l = arguments.length; i < l; i++) {
field = arguments[i];
if (has(this.hash[key].value, field)) {
@@ -683,6 +687,8 @@
this.hash[key] = { value: {}, type: 'hash' };
} else if (type !== 'hash') {
return false;
+ } else {
+ this.persist(key);
}
if (!has(this.hash[key].value, field)) {
@@ -761,6 +767,8 @@
this.hash[key] = { value: {}, type: 'hash' };
} else if (type !== 'hash') {
return false;
+ } else {
+ this.persist(key);
}
for(var i=1, l=arguments.length; i < l; i += 2) {
@@ -793,6 +801,7 @@
this.hash[key] = { value: {}, type: 'hash' };
update = false;
} else if (type === 'hash') {
+ this.persist(key);
update = has(this.hash[key].value, field);
} else {
return false;
@@ -809,8 +818,13 @@
// Set the value of a hash field, only if the field does not exist
//
EventVat.prototype.hsetnx = function(key, field, value /* ... */) {
- if (this.type(key) === 'none') {
+ var type = this.type(key);
+ if (type === 'none') {
this.hash[key] = { value: {}, type: 'hash' };
+ } else if (type !== 'hash') {
+ return false;
+ } else {
+ this.persist(key);
}
if (!has(this.hash[key].value, field)) {
@@ -899,6 +913,7 @@
//
EventVat.prototype.lpop = function(key) {
if (this.type(key) === 'list') {
+ this.persist(key);
var value = this.hash[key].value.shift();
this.emit('lpop ' + key, value);
this.emit('lpop', key, value);
@@ -920,6 +935,7 @@
} else if (type !== 'list') {
return false;
} else {
+ this.persist(key);
list = this.hash[key].value;
}
@@ -964,6 +980,7 @@
//
EventVat.prototype.lrem = function(key, count, value) {
if (this.type(key) === 'list') {
+ this.persist(key);
var list = this.hash[key].value;
var n = 0;
@@ -1013,6 +1030,7 @@
//
EventVat.prototype.lset = function(key, index, value) {
if (this.type(key) === 'list') {
+ this.persist(key);
var list = this.hash[key].value;
var len = list.length;
@@ -1037,6 +1055,7 @@
//
EventVat.prototype.ltrim = function(key, start, stop) {
if (this.type(key) === 'list') {
+ this.persist(key);
this.hash[key].value = this.hash[key].value.slice(start, stop);
this.emit('ltrim ' + key, start, stop);
this.emit('ltrim', key, start, stop);
@@ -1051,6 +1070,7 @@
//
EventVat.prototype.rpop = function(key) {
if (this.type(key) === 'list') {
+ this.persist(key);
var value = this.hash[key].value.pop();
this.emit('rpop ' + key, value);
this.emit('rpop', key, value);
@@ -1074,9 +1094,11 @@
} else if (dtype !== 'list') {
return false;
} else {
+ this.persist(destination);
dest = this.hash[destination].value;
}
+ this.persist(source);
var value = this.hash[source].value.pop();
dest.unshift(value);
this.emit('rpoplpush ' + source, destination, value);
@@ -1103,6 +1125,7 @@
} else if (type !== 'list') {
return false;
} else {
+ this.persist(key);
list = this.hash[key].value;
}

0 comments on commit 1b7a3ae

Please sign in to comment.