Skip to content

Commit

Permalink
0.0.3 release with support for sets, sorted sets, and hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Wilke committed Feb 24, 2015
1 parent 126112e commit 7ee3eb5
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 32 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ javascript.
- Mocha tests for all supported commands.
- Browser testing and compatibility determination.
* 1.0.0
- Support for different versions of mock redis that mimic different
redis versions.
- Support for multiple mock redis instances.
- Support for migrating data between mock redis instances.
- Support for persisting a mock redis instance.
* 2.0.0
- Support for migrating data from a mock redis instance to a real
redis instance.
- ?
- HyperLogLog support.

## Versions

* 0.0.3
- Set, sorted set, and hash support.
- Unit tests for implemented list, set, and sorted set commands.
- Bug squashes.
* 0.0.2
- Transaction support that works.
- Bug squashes.
Expand All @@ -30,3 +37,4 @@ javascript.
- DEPRECATED
- Initial implementation.
- Numerous bugs.
- Incomplete commands.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "git://github.com/wilkenstein/redis-mock-js.git"
},
"main": "redis-mock.js",
"version": "0.0.2",
"version": "0.0.3",
"devDependencies": {
"docco": "*",
"chance": "0.6.1",
Expand Down
258 changes: 247 additions & 11 deletions plato/files/redis_mock_js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ <h1>redis-mock.js</h1>
<div class="row">
<div class="col-md-6">
<h2 class="header">Maintainability <a href="http://blogs.msdn.com/b/codeanalysis/archive/2007/11/20/maintainability-index-range-and-meaning.aspx"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="A value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability." data-original-title="Maintainability Index"></i></a></h2>
<p class="stat">72.09</p>
<p class="stat">72.14</p>
</div>
<div class="col-md-6">
<h2 class="header">Lines of code <i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="Source Lines of Code / Logical Lines of Code" data-original-title="SLOC/LSLOC"></i></h2>
<p class="stat">839</p>
<p class="stat">1075</p>
</div>
</div>
<div class="row historical">
Expand All @@ -63,11 +63,11 @@ <h2 class="header">Lines of code <i class="icon icon-info-sign" rel="popover" da
<div class="row">
<div class="col-md-6">
<h2 class="header">Difficulty <a href="http://en.wikipedia.org/wiki/Halstead_complexity_measures"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="The difficulty measure is related to the difficulty of the program to write or understand." data-original-title="Difficulty"></i></a></h2>
<p class="stat">180.11</p>
<p class="stat">196.70</p>
</div>
<div class="col-md-6">
<h2 class="header">Estimated Errors <a href="http://en.wikipedia.org/wiki/Halstead_complexity_measures"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="Halstead's delivered bugs is an estimate for the number of errors in the implementation." data-original-title="Delivered Bugs"></i></a></h2>
<p class="stat">9.99</p>
<p class="stat">13.05</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -148,8 +148,11 @@ <h3 class="chart-header">By SLOC <i class="icon icon-info-sign" rel="popover" d
};
};

var gather = function (f) {
var gather = function (f, e) {
var end = f.length;
if (e) {
end = e;
}
return function () {
var idx, len = arguments.length;
var callback;
Expand All @@ -159,7 +162,7 @@ <h3 class="chart-header">By SLOC <i class="icon icon-info-sign" rel="popover" d
if (typeof arguments[idx] === &quot;function&quot;) {
callback = arguments[idx];
}
else if (arguments[idx]) {
else if (arguments[idx] !== null &amp;&amp; arguments[idx] !== undefined) {
list.push(arguments[idx]);
}
}
Expand Down Expand Up @@ -694,12 +697,13 @@ <h3 class="chart-header">By SLOC <i class="icon icon-info-sign" rel="popover" d
};

redismock.zadd = function (key, score, member, callback) {
var g = gather(this.zadd).apply(this, arguments);
var g = gather(this.zadd, 3).apply(this, arguments);
callback = g.callback;
return this
.ifType(key, &#039;zset&#039;, callback)
.thennx(function () { cache[zsets][key] = {}; })
.then(function () {
var count = 0;
g
.list
.map(function (elem, index) {
Expand All @@ -714,18 +718,250 @@ <h3 class="chart-header">By SLOC <i class="icon icon-info-sign" rel="popover" d
.forEach(function (sm) {
var score = sm[0];
var m = sm[1];
var noop = false;
if (!(score in cache[zsets][key])) {
cache[zsets][key][score] = [];
}
cache[zsets][key][score].push(m);
Object
.keys(cache[zsets][key])
.map(function (score) {
return [parseFloat(score), cache[zsets][key][score].indexOf(m)];
})
.filter(function (si) {
return si[1] !== -1;
})
.forEach(function (si) {
if (si[0] !== score) {
cache[zsets][key][si[0]].splice(si[1], 1);
}
else {
noop = true;
}
});
if (!noop) {
cache[zsets][key][score].push(m);
count += 1;
}
});
return cb(callback)(null, 1);
return cb(callback)(null, count);
})
.end();
};

redismock.zcard = function (key, callback) {
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
var count = Object.keys(cache[zsets][key]).reduce(function (cnt, score) {
return cnt + cache[zsets][key][score].length;
}, 0);
return cb(callback)(null, count);
})
.thennx(function () { return cb(callback)(null, 0); })
.end();
};

redismock.zcount = function (key, min, max, callback) {
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
var count = Object
.keys(cache[zsets][key])
.map(function (score) {
return parseFloat(score);
})
.filter(function (score) {
return min &lt;= score &amp;&amp; score &lt;= max;
})
.reduce(function (cnt, score) {
return cnt + cache[zsets][key][score].length;
}, 0);
return cb(callback)(null, count);
})
.thennx(function () { return cb(callback)(null, 0); })
.end();
};

/*redismock.zrangebyscore = function (key, min, max, callback) {
};*/
redismock.zrange = function (key, start, stop, callback) {
var withscores = false;
if (typeof callback !== &quot;function&quot; &amp;&amp; callback === &quot;withscores&quot;) {
withscores = true;
callback = arguments[4];
}
if (start &lt; 0) {
start = this.zcard(key) + start;
}
if (stop &lt; 0) {
stop = this.zcard(key) + stop;
}
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
var index = 0;
var arr = [];
Object
.keys(cache[zsets][key])
.map(function (score) {
return parseFloat(score);
})
.sort()
.some(function (score) {
cache[zsets][key][score].forEach(function (member) {
if (start &lt;= index &amp;&amp; index &lt;= stop) {
arr.push(member);
if (withscores) {
arr.push(score);
}
}
index += 1;
});
if (index &gt; stop) {
return true;
}
return false;
});
return cb(callback)(null, arr);
})
.thennx(function () { return cb(callback)(null, []); })
.end();
};

redismock.zrangebyscore = function (key, min, max, callback) {
var withscores = false;
var limitOffset = -1, limitCount = -1;
var idx, len;
var arr = [], offset;
var minInclusive = true, maxInclusive = true;
if (typeof callback !== &quot;function&quot;) {
len = arguments.length;
for (idx = 3; idx &lt; len; idx += 1) {
if (arguments[idx] === &#039;withscores&#039;) {
withscores = true;
}
if (typeof arguments[idx] === &quot;function&quot;) {
callback = arguments[idx];
}
if (arguments[idx] === &quot;limit&quot;) {
limitOffset = arguments[idx + 1];
limitCount = arguments[idx + 2];
}
}
}
if (min === &#039;-inf&#039;) {
min = Number.NEGATIVE_INFINITY;
}
if (min === &#039;+inf&#039;) {
min = Number.POSITIVE_INFINITY;
}
if (max === &#039;-inf&#039;) {
max = Number.NEGATIVE_INFINITY;
}
if (max === &#039;+inf&#039;) {
max = Number.POSITIVE_INFINITY;
}
if (min.toString().charAt(0) === &#039;(&#039;) {
minInclusive = false;
min = parseFloat(min.toString().substr(1));
}
if (max.toString().charAt(0) === &#039;(&#039;) {
maxInclusive = false;
max = parseFloat(max.toString().substr(1));
}
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
Object
.keys(cache[zsets][key])
.map(function (score) {
return parseFloat(score);
})
.sort()
.some(function (score) {
cache[zsets][key][score].some(function (member) {
if (((minInclusive &amp;&amp; min &lt;= score) || (!minInclusive &amp;&amp; min &lt; score)) &amp;&amp; ((maxInclusive &amp;&amp; score &lt;= max) || (!maxInclusive &amp;&amp; score &lt; max))) {
if (limitOffset !== -1 &amp;&amp; offset &gt;= limitOffset) {
if (limitCount !== -1) {
if (arr.length &lt; limitCount) {
arr.push(member);
if (withscores) {
arr.push(score);
}
}
else {
return true;
}
}
}
else {
arr.push(member);
if (withscores) {
arr.push(score);
}
}
}
offset += 1;
return false;
});
if (limitCount !== -1 &amp;&amp; arr.length === limitCount) {
return true;
}
return false;
});
return cb(callback)(null, arr);
})
.thennx(function () { return cb(callback)(null, []); })
.end();
};

redismock.zrank = function (key, member, callback) {
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
var idx = 0;
var found = Object
.keys(cache[zsets][key])
.map(function (score) {
return parseFloat(score);
})
.sort()
.some(function (score) {
if (cache[zsets][key][score].indexOf(member) !== -1) {
return true;
}
idx += 1;
return false;
});
if (!found) {
return cb(callback)(null, null);
}
return cb(callback)(null, idx);
})
.thennx(function () { return cb(callback)(null, null); })
.end();
};

redismock.zrem = function (key, member, callback) {
var count = 0;
var g = gather(this.zrem).apply(this, arguments);
callback = g.callback;
return this
.ifType(key, &#039;zset&#039;, callback)
.thenex(function () {
g.list.forEach(function (m) {
Object
.keys(cache[zsets][key])
.forEach(function (score) {
var idx = cache[zsets][key][score].indexOf(m);
if (idx !== -1) {
cache[zsets][key][score].splice(idx, 1);
count += 1;
}
});
});
})
.then(function () { return cb(callback)(null, count); })
.end();
};

redismock.hdel = function (key, field, callback) {
var count = 0;
Expand Down
2 changes: 1 addition & 1 deletion plato/files/redis_mock_js/report.history.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plato/files/redis_mock_js/report.history.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"date":"Mon, 23 Feb 2015 00:10:53 GMT","sloc":521,"lloc":349,"functions":43,"deliveredBugs":5.382888308302201,"maintainability":63.67301240562197,"lintErrors":0,"difficulty":130.0892857142857},{"date":"Mon, 23 Feb 2015 04:12:07 GMT","sloc":626,"lloc":387,"functions":97,"deliveredBugs":7.050185813268926,"maintainability":72.49776783403156,"lintErrors":0,"difficulty":158.63125000000002},{"date":"Mon, 23 Feb 2015 04:12:31 GMT","sloc":627,"lloc":388,"functions":97,"deliveredBugs":7.057785726111113,"maintainability":72.47119936706054,"lintErrors":0,"difficulty":158.84375},{"date":"Mon, 23 Feb 2015 06:19:17 GMT","sloc":649,"lloc":403,"functions":100,"deliveredBugs":7.357820689715222,"maintainability":72.31160923765782,"lintErrors":0,"difficulty":162.28220858895705},{"date":"Mon, 23 Feb 2015 08:36:35 GMT","sloc":750,"lloc":468,"functions":116,"deliveredBugs":8.65534346565204,"maintainability":72.31104075865707,"lintErrors":0,"difficulty":161.67098445595857},{"date":"Mon, 23 Feb 2015 09:54:24 GMT","sloc":839,"lloc":528,"functions":129,"deliveredBugs":9.98958161922457,"maintainability":72.09247379589301,"lintErrors":0,"difficulty":180.1081730769231}]
[{"date":"Mon, 23 Feb 2015 00:10:53 GMT","sloc":521,"lloc":349,"functions":43,"deliveredBugs":5.382888308302201,"maintainability":63.67301240562197,"lintErrors":0,"difficulty":130.0892857142857},{"date":"Mon, 23 Feb 2015 04:12:07 GMT","sloc":626,"lloc":387,"functions":97,"deliveredBugs":7.050185813268926,"maintainability":72.49776783403156,"lintErrors":0,"difficulty":158.63125000000002},{"date":"Mon, 23 Feb 2015 04:12:31 GMT","sloc":627,"lloc":388,"functions":97,"deliveredBugs":7.057785726111113,"maintainability":72.47119936706054,"lintErrors":0,"difficulty":158.84375},{"date":"Mon, 23 Feb 2015 06:19:17 GMT","sloc":649,"lloc":403,"functions":100,"deliveredBugs":7.357820689715222,"maintainability":72.31160923765782,"lintErrors":0,"difficulty":162.28220858895705},{"date":"Mon, 23 Feb 2015 08:36:35 GMT","sloc":750,"lloc":468,"functions":116,"deliveredBugs":8.65534346565204,"maintainability":72.31104075865707,"lintErrors":0,"difficulty":161.67098445595857},{"date":"Mon, 23 Feb 2015 09:54:24 GMT","sloc":839,"lloc":528,"functions":129,"deliveredBugs":9.98958161922457,"maintainability":72.09247379589301,"lintErrors":0,"difficulty":180.1081730769231},{"date":"Tue, 24 Feb 2015 02:43:32 GMT","sloc":1075,"lloc":663,"functions":164,"deliveredBugs":13.05004686723495,"maintainability":72.1449170251016,"lintErrors":0,"difficulty":196.69628099173553}]
2 changes: 1 addition & 1 deletion plato/files/redis_mock_js/report.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plato/files/redis_mock_js/report.json

Large diffs are not rendered by default.

Loading

0 comments on commit 7ee3eb5

Please sign in to comment.