ioredis-mock
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,2 +0,2 @@ | ||
var RedisMock = require('ioredis-mock').default | ||
var RedisMock = require('ioredis-mock').default; | ||
var redis = new RedisMock({ | ||
@@ -14,2 +14,2 @@ data: { | ||
await redis.incr('user_next') | ||
await redis.incr('user_next'); |
110
lib/index.js
@@ -22,3 +22,5 @@ 'use strict'; | ||
var RedisMock = function () { | ||
function RedisMock(_ref) { | ||
function RedisMock() { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? { data: {} } : arguments[0]; | ||
var data = _ref.data; | ||
@@ -32,23 +34,42 @@ | ||
_createClass(RedisMock, [{ | ||
key: 'get', | ||
value: function get(key) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
return resolve(_this.data.hasOwnProperty(key) ? _this.data[key] : null); | ||
}); | ||
} | ||
}, { | ||
key: 'incr', | ||
value: function incr(key) { | ||
var _this = this; | ||
var _this2 = this; | ||
return new Promise(function (resolve) { | ||
var curVal = Number(_this.data[key]); | ||
var incVal = curVal + 1; | ||
resolve(incVal.toString()); | ||
var curVal = Number(_this2.data[key]); | ||
_this2.data[key] = curVal + 1; | ||
resolve(_this2.data[key].toString()); | ||
}); | ||
} | ||
}, { | ||
key: 'set', | ||
value: function set(key, value) { | ||
var _this3 = this; | ||
return new Promise(function (resolve) { | ||
_this3.data[key] = value; | ||
resolve('OK'); | ||
}); | ||
} | ||
}, { | ||
key: 'hsetnx', | ||
value: function hsetnx(key, hashKey, hashVal) { | ||
var _this2 = this; | ||
var _this4 = this; | ||
return new Promise(function (resolve) { | ||
if (!_this2.data.hasOwnProperty(key)) { | ||
_this2.data[key] = {}; | ||
if (!_this4.data.hasOwnProperty(key)) { | ||
_this4.data[key] = {}; | ||
} | ||
var exists = _this2.data[key].hasOwnProperty(hashKey); | ||
_this2.data[key][hashKey] = hashVal; | ||
var exists = _this4.data[key].hasOwnProperty(hashKey); | ||
_this4.data[key][hashKey] = hashVal; | ||
@@ -61,3 +82,3 @@ resolve(!exists); | ||
value: function hmset(key) { | ||
var _this3 = this; | ||
var _this5 = this; | ||
@@ -69,7 +90,7 @@ for (var _len = arguments.length, hmsetData = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
return new Promise(function (resolve) { | ||
if (!_this3.data.hasOwnProperty(key)) { | ||
_this3.data[key] = {}; | ||
if (!_this5.data.hasOwnProperty(key)) { | ||
_this5.data[key] = {}; | ||
} | ||
for (var i = 0; i < hmsetData.length; i += 2) { | ||
_this3.data[key][hmsetData[i]] = hmsetData[i + 1]; | ||
_this5.data[key][hmsetData[i]] = hmsetData[i + 1]; | ||
} | ||
@@ -82,8 +103,17 @@ | ||
key: 'sadd', | ||
value: function sadd(key, val) { | ||
var _this4 = this; | ||
value: function sadd(key) { | ||
var _this6 = this; | ||
for (var _len2 = arguments.length, vals = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
vals[_key2 - 1] = arguments[_key2]; | ||
} | ||
return new Promise(function (resolve) { | ||
_this4.data[key].push(val); | ||
resolve(1); | ||
var _data$key; | ||
if (!_this6.data.hasOwnProperty(key)) { | ||
_this6.data[key] = []; | ||
} | ||
(_data$key = _this6.data[key]).push.apply(_data$key, vals); | ||
resolve(vals.length); | ||
}); | ||
@@ -93,9 +123,15 @@ } | ||
key: 'srem', | ||
value: function srem(key, val) { | ||
var _this5 = this; | ||
value: function srem(key) { | ||
var _this7 = this; | ||
for (var _len3 = arguments.length, vals = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
vals[_key3 - 1] = arguments[_key3]; | ||
} | ||
return new Promise(function (resolve) { | ||
var index = _this5.data[key].indexOf(val); | ||
_this5.data[key].splice(index, 1); | ||
resolve(1); | ||
vals.forEach(function (val) { | ||
var index = _this7.data[key].indexOf(val); | ||
_this7.data[key].splice(index, 1); | ||
}); | ||
resolve(vals.length); | ||
}); | ||
@@ -106,6 +142,6 @@ } | ||
value: function hget(key, hashKey) { | ||
var _this6 = this; | ||
var _this8 = this; | ||
return new Promise(function (resolve) { | ||
return resolve(_this6.data[key][hashKey]); | ||
return resolve(_this8.data[key][hashKey]); | ||
}); | ||
@@ -116,6 +152,6 @@ } | ||
value: function hvals(key) { | ||
var _this7 = this; | ||
var _this9 = this; | ||
return new Promise(function (resolve) { | ||
resolve(_lodash2.default.values(_this7.data[key])); | ||
resolve(_lodash2.default.values(_this9.data[key])); | ||
}); | ||
@@ -126,6 +162,6 @@ } | ||
value: function hgetall(key) { | ||
var _this8 = this; | ||
var _this10 = this; | ||
return new Promise(function (resolve) { | ||
resolve(_this8.data[key]); | ||
resolve(_this10.data[key]); | ||
}); | ||
@@ -136,6 +172,6 @@ } | ||
value: function smembers(key) { | ||
var _this9 = this; | ||
var _this11 = this; | ||
return new Promise(function (resolve) { | ||
resolve(_this9.data[key]); | ||
resolve(_this11.data[key]); | ||
}); | ||
@@ -146,6 +182,6 @@ } | ||
value: function sismember(key, val) { | ||
var _this10 = this; | ||
var _this12 = this; | ||
return new Promise(function (resolve) { | ||
resolve(_this10.data[key].indexOf(val) !== -1); | ||
resolve(_this12.data[key].indexOf(val) !== -1); | ||
}); | ||
@@ -156,6 +192,6 @@ } | ||
value: function hset(key, hashKey, hashVal) { | ||
var _this11 = this; | ||
var _this13 = this; | ||
return new Promise(function (resolve) { | ||
_this11.data[key][hashKey] = hashVal; | ||
_this13.data[key][hashKey] = hashVal; | ||
resolve('OK'); | ||
@@ -167,3 +203,3 @@ }); | ||
value: function multi(batch) { | ||
var _this12 = this; | ||
var _this14 = this; | ||
@@ -179,3 +215,3 @@ this.batch = batch.map(function (_ref2) { | ||
return (_command = _this12[command]).bind.apply(_command, [_this12].concat(_toConsumableArray(options))); | ||
return (_command = _this14[command]).bind.apply(_command, [_this14].concat(_toConsumableArray(options))); | ||
}); | ||
@@ -182,0 +218,0 @@ |
{ | ||
"name": "ioredis-mock", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "This library emulates ioredis by performing all operations in-memory.", | ||
@@ -8,2 +8,4 @@ "main": "./lib", | ||
"clean": "rimraf lib", | ||
"prepublish": "npm run clean && npm run build", | ||
"preversion": "node scripts/update-compat", | ||
"build": "mkdirp lib && babel src --out-file lib/index.js", | ||
@@ -32,2 +34,5 @@ "build:watch": "npm run build -- --watch", | ||
"homepage": "https://github.com/stipsan/ioredis-mock#readme", | ||
"peerDependencies": { | ||
"ioredis": "2.x" | ||
}, | ||
"devDependencies": { | ||
@@ -46,2 +51,3 @@ "babel-cli": "6.10.1", | ||
"growl": "1.9.2", | ||
"ioredis": "2.0.1", | ||
"istanbul": "1.0.0-alpha.2", | ||
@@ -53,5 +59,5 @@ "mkdirp": "0.5.1", | ||
"dependencies": { | ||
"ioredis": "2.0.1", | ||
"lodash": "4.13.1" | ||
"lodash": "4.13.1", | ||
"redis-commands": "1.2.0" | ||
} | ||
} |
@@ -42,21 +42,5 @@ ioredis-mock | ||
## Mocked ioredis features | ||
## [Mocked ioredis features](compat.md) | ||
* incr | ||
* get | ||
* set | ||
* hsetnx | ||
* hmset | ||
* sadd | ||
* srem | ||
* hget | ||
* hvals | ||
* hgetall | ||
* smembers | ||
* sismember | ||
* hset | ||
* multi | ||
* exec | ||
# Roadmap | ||
## Roadmap | ||
This project started off as just an utility in [another project](https://github.com/stipsan/epic) and just recently got open sourced to benefit the rest of the ioredis community. This means there's work to do before it's feature complete: | ||
@@ -71,4 +55,4 @@ - [x] Setup testing suite for the library itself. | ||
# I need a feature not listed here | ||
## I need a feature not listed here | ||
Just create an issue and tell us all about it or submit a PR with it! :-) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
19662
13
216
3
17
57
1
+ Addedredis-commands@1.2.0
+ Addedcluster-key-slot@1.1.2(transitive)
+ Addedioredis@2.5.0(transitive)
+ Addedredis-commands@1.2.0(transitive)
- Removedioredis@2.0.1
- Removedioredis@2.0.1(transitive)
- Removedredis-commands@1.7.0(transitive)