ioredis-mock
Advanced tools
Comparing version 1.15.0 to 2.0.0
@@ -8,2 +8,48 @@ # ioredis-mock change log | ||
## [2.0.0] - 2016-10-03 | ||
Bumping the version to v2 as there are fixes in this release that are breaking changes. | ||
### Added | ||
* `flushdb` command. | ||
### Changed | ||
* Command arguments is now transformed to strings before being passed to the command itself helping the mock behave more like a real ioredis client. | ||
### Fixed | ||
* `append` updated to return an integer. | ||
* `dbsize` updated to return an integer. | ||
* `decr` updated to return an integer. | ||
* `decrby` updated to return an integer. | ||
* `expire` updated to return an integer. | ||
* `expireat` updated to return an integer. | ||
* `hdel` updated to return an integer. | ||
* `hexists` updated to return an integer. | ||
* `hincrby` updated to return an integer. | ||
* `hlen` updated to return an integer. | ||
* `hset` updated to return an integer. | ||
* `hsetnx` updated to return an integer. | ||
* `hstrlen` updated to return an integer. | ||
* `incr` updated to return an integer. | ||
* `incrby` updated to return an integer. | ||
* `lpush` updated to return an integer. | ||
* `lpushx` updated to return an integer. | ||
* `mget` required a single array argument, updated to use multiple arguments (single array support will be added later when ioredis Argument Transformers is properly implemented). | ||
* `msetnx` updated to return an integer. | ||
* `persist` updated to return an integer. | ||
* `pexpire` updated to return an integer. | ||
* `pexpireat` updated to return an integer. | ||
* `pttl` updated to return an integer. | ||
* `renamenx` updated to return an integer. | ||
* `rpush` updated to return an integer. | ||
* `rpushx` updated to return an integer. | ||
* `scard` updated to return an integer. | ||
* `setnx` updated to return an integer. | ||
* `sismember` updated to return an integer. | ||
* `strlen` updated to return an integer. | ||
* `ttl` updated to return an integer. | ||
### Deprecated | ||
* `hmset` no longer accepts passing an object with keys and values directly. This will be added later when ioredis Argument Transformers is properly implemented. | ||
## [1.15.0] - 2016-10-03 | ||
@@ -243,2 +289,3 @@ ### Added | ||
[2.0.0]: https://github.com/stipsan/ioredis-mock/compare/v1.15.0...v2.0.0 | ||
[1.15.0]: https://github.com/stipsan/ioredis-mock/compare/v1.14.0...v1.15.0 | ||
@@ -245,0 +292,0 @@ [1.14.0]: https://github.com/stipsan/ioredis-mock/compare/v1.13.1...v1.14.0 |
@@ -1,2 +0,2 @@ | ||
## Supported commands  | ||
## Supported commands  | ||
@@ -34,3 +34,3 @@ | redis | ioredis | ioredis-mock | | ||
|[flushall](http://redis.io/commands/FLUSHALL)|:white_check_mark:|:white_check_mark:| | ||
|[flushdb](http://redis.io/commands/FLUSHDB)|:white_check_mark:|:x:| | ||
|[flushdb](http://redis.io/commands/FLUSHDB)|:white_check_mark:|:white_check_mark:| | ||
|[geoadd](http://redis.io/commands/GEOADD)|:white_check_mark:|:x:| | ||
@@ -37,0 +37,0 @@ |[geodist](http://redis.io/commands/GEODIST)|:white_check_mark:|:x:| |
@@ -14,2 +14,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function command(emulate) { | ||
@@ -29,6 +31,11 @@ return function () { | ||
// transform arguments to strings to simulate real ioredis behavior | ||
var stringArgs = args.map(function (arg) { | ||
return arg.toString(); | ||
}); | ||
return new _bluebird2.default(function (resolve) { | ||
return resolve(emulate.apply(undefined, args)); | ||
return resolve(emulate.apply(undefined, _toConsumableArray(stringArgs))); | ||
}).asCallback(callback); | ||
}; | ||
} |
@@ -12,3 +12,3 @@ 'use strict'; | ||
this.data.set(key, this.data.get(key) + value); | ||
return this.data.get(key).length.toString(); | ||
return this.data.get(key).length; | ||
} |
@@ -8,3 +8,3 @@ "use strict"; | ||
function dbsize() { | ||
return this.data.keys().length.toString(); | ||
return this.data.keys().length; | ||
} |
@@ -9,4 +9,5 @@ "use strict"; | ||
var curVal = Number(this.data.get(key)); | ||
this.data.set(key, (curVal - 1).toString()); | ||
return this.data.get(key); | ||
var nextVal = curVal - 1; | ||
this.data.set(key, nextVal.toString()); | ||
return nextVal; | ||
} |
@@ -11,4 +11,5 @@ "use strict"; | ||
var curVal = Number(this.data.get(key)); | ||
this.data.set(key, (curVal - decrement).toString()); | ||
return this.data.get(key); | ||
var nextVal = curVal - parseInt(decrement, 10); | ||
this.data.set(key, nextVal.toString()); | ||
return nextVal; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,3 +15,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,3 +15,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -7,4 +7,6 @@ "use strict"; | ||
exports.getrange = getrange; | ||
function getrange(key, start, end) { | ||
function getrange(key, s, e) { | ||
var val = this.data.get(key); | ||
var start = parseInt(s, 10); | ||
var end = parseInt(e, 10); | ||
@@ -11,0 +13,0 @@ if (end === -1) { |
@@ -20,3 +20,3 @@ "use strict"; | ||
return false; | ||
}).length.toString(); | ||
}).length; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", { | ||
function hexists(key, field) { | ||
return {}.hasOwnProperty.call(this.data.get(key), field) ? '1' : '0'; | ||
return {}.hasOwnProperty.call(this.data.get(key), field) ? 1 : 0; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -14,10 +14,11 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
this.data.set(key, _defineProperty({}, field, 0)); | ||
this.data.set(key, _defineProperty({}, field, '0')); | ||
} | ||
if (!{}.hasOwnProperty.call(this.data.get(key), field)) { | ||
this.data.get(key)[field] = 0; | ||
this.data.get(key)[field] = '0'; | ||
} | ||
var curVal = Number(this.data.get(key)[field]); | ||
this.data.get(key)[field] = curVal + increment; | ||
return this.data.get(key)[field].toString(); | ||
var nextVal = curVal + parseInt(increment, 10); | ||
this.data.get(key)[field] = nextVal.toString(); | ||
return nextVal; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -12,6 +12,6 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
this.data.set(key, _defineProperty({}, field, 0)); | ||
this.data.set(key, _defineProperty({}, field, '0')); | ||
} | ||
if (!{}.hasOwnProperty.call(this.data.get(key), field)) { | ||
this.data.get(key)[field] = 0; | ||
this.data.get(key)[field] = '0'; | ||
} | ||
@@ -18,0 +18,0 @@ var curVal = parseFloat(this.data.get(key)[field]); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", { | ||
function hlen(key) { | ||
return this.data.has(key) ? Object.keys(this.data.get(key)).length.toString() : '0'; | ||
return this.data.has(key) ? Object.keys(this.data.get(key)).length : 0; | ||
} |
@@ -7,9 +7,2 @@ 'use strict'; | ||
exports.hmset = hmset; | ||
var _objectAssign = require('object-assign'); | ||
var _objectAssign2 = _interopRequireDefault(_objectAssign); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function hmset(key) { | ||
@@ -24,10 +17,4 @@ if (!this.data.has(key)) { | ||
if (hmsetData.length === 1) { | ||
// assume object | ||
this.data.set(key, (0, _objectAssign2.default)({}, hmsetData[0])); | ||
} else { | ||
// assume array | ||
for (var i = 0; i < hmsetData.length; i += 2) { | ||
this.data.get(key)[hmsetData[i]] = hmsetData[i + 1]; | ||
} | ||
for (var i = 0; i < hmsetData.length; i += 2) { | ||
this.data.get(key)[hmsetData[i]] = hmsetData[i + 1]; | ||
} | ||
@@ -34,0 +21,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { | ||
var reply = '1'; | ||
var reply = 1; | ||
var hash = this.data.get(key); | ||
if ({}.hasOwnProperty.call(hash, hashKey)) { | ||
reply = '0'; | ||
reply = 0; | ||
} | ||
@@ -19,0 +19,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -15,6 +15,6 @@ Object.defineProperty(exports, "__esModule", { | ||
return '1'; | ||
return 1; | ||
} | ||
return '0'; | ||
return 0; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", { | ||
function hstrlen(key, field) { | ||
return this.data.has(key) && {}.hasOwnProperty.call(this.data.get(key), field) ? this.data.get(key)[field].length.toString() : '0'; | ||
return this.data.has(key) && {}.hasOwnProperty.call(this.data.get(key), field) ? this.data.get(key)[field].length : 0; | ||
} |
@@ -12,4 +12,5 @@ 'use strict'; | ||
var curVal = Number(this.data.get(key)); | ||
this.data.set(key, (curVal + 1).toString()); | ||
return this.data.get(key); | ||
var nextVal = curVal + 1; | ||
this.data.set(key, nextVal.toString()); | ||
return nextVal; | ||
} |
@@ -11,4 +11,5 @@ "use strict"; | ||
var curVal = Number(this.data.get(key)); | ||
this.data.set(key, (curVal + increment).toString()); | ||
return this.data.get(key); | ||
var nextVal = curVal + parseInt(increment, 10); | ||
this.data.set(key, nextVal.toString()); | ||
return nextVal; | ||
} |
@@ -187,2 +187,14 @@ 'use strict'; | ||
var _flushdb = require('./flushdb'); | ||
Object.keys(_flushdb).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _flushdb[key]; | ||
} | ||
}); | ||
}); | ||
var _get = require('./get'); | ||
@@ -189,0 +201,0 @@ |
@@ -7,6 +7,7 @@ "use strict"; | ||
exports.lindex = lindex; | ||
function lindex(key, index) { | ||
function lindex(key, i) { | ||
if (this.data.has(key) && !(this.data.get(key) instanceof Array)) { | ||
throw new Error("Key " + key + " does not contain a list"); | ||
} | ||
var index = parseInt(i, 10); | ||
var list = this.data.get(key) || []; | ||
@@ -13,0 +14,0 @@ var item = list[index < 0 ? list.length + index : index]; |
@@ -22,3 +22,3 @@ "use strict"; | ||
this.data.set(key, list); | ||
return length.toString(); | ||
return length; | ||
} |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -10,6 +10,7 @@ "use strict"; | ||
function lrem(key, count, value) { | ||
function lrem(key, c, value) { | ||
if (this.data.has(key) && !(this.data.get(key) instanceof Array)) { | ||
return 0; | ||
} | ||
var count = parseInt(c, 10); | ||
var list = [].concat(_toConsumableArray(this.data.get(key) || [])); | ||
@@ -16,0 +17,0 @@ var indexFun = (count < 0 ? [].lastIndexOf : [].indexOf).bind(list); |
@@ -7,3 +7,3 @@ 'use strict'; | ||
exports.lset = lset; | ||
function lset(key, index, value) { | ||
function lset(key, i, value) { | ||
if (!this.data.has(key)) { | ||
@@ -17,2 +17,3 @@ throw new Error('no such key'); | ||
var index = parseInt(i, 10); | ||
var list = this.data.get(key) || []; | ||
@@ -19,0 +20,0 @@ list[index < 0 ? list.length + index : index] = value; |
@@ -7,5 +7,9 @@ "use strict"; | ||
exports.mget = mget; | ||
function mget(keys) { | ||
function mget() { | ||
var _this = this; | ||
for (var _len = arguments.length, keys = Array(_len), _key = 0; _key < _len; _key++) { | ||
keys[_key] = arguments[_key]; | ||
} | ||
return keys.map(function (key) { | ||
@@ -12,0 +16,0 @@ return _this.data.has(key) ? _this.data.get(key) : null; |
@@ -13,3 +13,3 @@ 'use strict'; | ||
if (this.data.has(arguments.length <= i + 0 ? undefined : arguments[i + 0])) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -22,3 +22,3 @@ } | ||
return '1'; | ||
return 1; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
if (!this.expires.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -19,3 +19,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,3 +15,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,3 +15,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '-2'; | ||
return -2; | ||
} | ||
if (!this.expires.has(key)) { | ||
return '-1'; | ||
return -1; | ||
} | ||
return Math.round(this.expires.get(key) - Date.now()).toString(); | ||
return Math.ceil(this.expires.get(key) - Date.now()); | ||
} |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (this.data.has(newKey)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -18,3 +18,3 @@ | ||
return '1'; | ||
return 1; | ||
} |
@@ -19,3 +19,3 @@ "use strict"; | ||
this.data.set(key, list); | ||
return length.toString(); | ||
return length; | ||
} |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (!this.data.has(key)) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -17,3 +17,3 @@ 'use strict'; | ||
if (!set) { | ||
return '0'; | ||
return 0; | ||
} | ||
@@ -23,3 +23,3 @@ if (!(set instanceof _es6Set2.default)) { | ||
} | ||
return this.data.get(key).size.toString(); | ||
return this.data.get(key).size; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -11,6 +11,6 @@ Object.defineProperty(exports, "__esModule", { | ||
return '1'; | ||
return 1; | ||
} | ||
return '0'; | ||
return 0; | ||
} |
@@ -8,3 +8,3 @@ "use strict"; | ||
function sismember(key, val) { | ||
return this.data.get(key).has(val); | ||
return this.data.get(key).has(val) ? 1 : 0; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", { | ||
function strlen(key) { | ||
return this.data.has(key) ? this.data.get(key).length.toString() : '0'; | ||
return this.data.has(key) ? this.data.get(key).length : 0; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "__esModule", { | ||
if (!this.data.has(key)) { | ||
return '-2'; | ||
return -2; | ||
} | ||
if (!this.expires.has(key)) { | ||
return '-1'; | ||
return -1; | ||
} | ||
return Math.round((this.expires.get(key) - Date.now()) / 1000).toString(); | ||
return Math.ceil((this.expires.get(key) - Date.now()) / 1000); | ||
} |
{ | ||
"name": "ioredis-mock", | ||
"version": "1.15.0", | ||
"version": "2.0.0", | ||
"description": "This library emulates ioredis by performing all operations in-memory.", | ||
@@ -60,3 +60,3 @@ "main": "./lib", | ||
"coveralls": "2.11.14", | ||
"eslint": "3.6.1", | ||
"eslint": "3.7.1", | ||
"eslint-config-airbnb-base": "8.0.0", | ||
@@ -63,0 +63,0 @@ "eslint-plugin-import": "2.0.0", |
86166
97
1948