ioredis-mock
Advanced tools
Comparing version 5.9.0 to 6.0.0
@@ -6,12 +6,12 @@ "use strict"; | ||
}); | ||
exports.Command = void 0; | ||
exports.default = command; | ||
exports.isInSubscriberMode = isInSubscriberMode; | ||
exports.isNotConnected = isNotConnected; | ||
exports.throwIfInSubscriberMode = throwIfInSubscriberMode; | ||
exports.throwIfNotConnected = throwIfNotConnected; | ||
exports.throwIfCommandIsNotAllowed = throwIfCommandIsNotAllowed; | ||
exports.processArguments = processArguments; | ||
exports.processReply = processReply; | ||
exports.safelyExecuteCommand = safelyExecuteCommand; | ||
exports.default = command; | ||
exports.Command = void 0; | ||
exports.throwIfCommandIsNotAllowed = throwIfCommandIsNotAllowed; | ||
exports.throwIfInSubscriberMode = throwIfInSubscriberMode; | ||
exports.throwIfNotConnected = throwIfNotConnected; | ||
@@ -18,0 +18,0 @@ var _lodash = _interopRequireDefault(require("lodash")); |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.default = patternMatchesString; | ||
exports.stringmatchlen = stringmatchlen; | ||
exports.default = patternMatchesString; | ||
@@ -10,0 +10,0 @@ /* |
@@ -6,6 +6,7 @@ "use strict"; | ||
}); | ||
exports.defineKeys = defineKeys; | ||
exports.customCommand = void 0; | ||
exports.defineArgv = defineArgv; | ||
exports.defineCommand = defineCommand; | ||
exports.customCommand = exports.defineRedisObject = void 0; | ||
exports.defineKeys = defineKeys; | ||
exports.defineRedisObject = void 0; | ||
@@ -12,0 +13,0 @@ var _fengari = _interopRequireDefault(require("fengari")); |
@@ -6,7 +6,7 @@ "use strict"; | ||
}); | ||
exports.slice = slice; | ||
exports.filterPredicate = filterPredicate; | ||
exports.getWithScoresAndLimit = getWithScoresAndLimit; | ||
exports.offsetAndLimit = offsetAndLimit; | ||
exports.parseLimit = parseLimit; | ||
exports.filterPredicate = filterPredicate; | ||
exports.getWithScoresAndLimit = getWithScoresAndLimit; | ||
exports.slice = slice; | ||
@@ -13,0 +13,0 @@ function slice(arr, start, end) { |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.createData = createData; | ||
exports.createSharedData = createSharedData; | ||
exports.createData = createData; | ||
@@ -10,0 +10,0 @@ var _lodash = require("lodash"); |
@@ -6,4 +6,4 @@ "use strict"; | ||
}); | ||
exports.createExpires = createExpires; | ||
exports.createSharedExpires = createSharedExpires; | ||
exports.createExpires = createExpires; | ||
@@ -10,0 +10,0 @@ function createSharedExpires() { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.dispose = exports.init = void 0; | ||
exports.init = exports.dispose = void 0; | ||
@@ -9,0 +9,0 @@ var _fengari = _interopRequireDefault(require("fengari")); |
@@ -55,3 +55,3 @@ { | ||
"coveralls": "^3.1.0", | ||
"esbuild": "^0.11.12", | ||
"esbuild": "^0.14.0", | ||
"eslint": "^7.24.0", | ||
@@ -129,3 +129,3 @@ "eslint-config-airbnb-base": "^14.2.1", | ||
"runkitExampleFilename": "example.js", | ||
"version": "5.9.0" | ||
"version": "6.0.0" | ||
} |
@@ -27,4 +27,4 @@ # ioredis-mock · [](https://npm-stat.com/charts.html?package=ioredis-mock) [](https://www.npmjs.com/package/ioredis-mock) [](compat.md) [](https://github.com/semantic-release/semantic-release) | ||
```js | ||
var Redis = require('ioredis-mock'); | ||
var redis = new Redis({ | ||
const Redis = require('ioredis-mock'); | ||
const redis = new Redis({ | ||
// `options.data` does not exist in `ioredis`, only `ioredis-mock` | ||
@@ -44,2 +44,45 @@ data: { | ||
### Breaking API changes from v5 | ||
Before v6, each instance of `ioredis-mock` lived in isolation: | ||
```js | ||
const Redis = require('ioredis-mock'); | ||
const redis1 = new Redis(); | ||
const redis2 = new Redis(); | ||
await redis1.set('foo', 'bar'); | ||
console.log(await redis1.get('foo'), await redis2.get('foo')); // 'bar', null | ||
``` | ||
In v6 the [internals were rewritten](https://github.com/stipsan/ioredis-mock/pull/1110) to behave more like real life redis, if the host and port is the same, the context is now shared: | ||
```js | ||
const Redis = require('ioredis-mock'); | ||
const redis1 = new Redis(); | ||
const redis2 = new Redis(); | ||
const redis3 = new Redis({ port: 6380 }); // 6379 is the default port | ||
await redis1.set('foo', 'bar'); | ||
console.log( | ||
await redis1.get('foo'), // 'bar' | ||
await redis2.get('foo'), // 'bar' | ||
await redis3.get('foo') // null | ||
); | ||
``` | ||
And since `ioredis-mock` now persist data between instances, you'll [likely](https://github.com/luin/ioredis/blob/8278ec0a435756c54ba4f98587aec1a913e8b7d3/test/helpers/global.ts#L8) need to run `flushall` between testing suites: | ||
```js | ||
const Redis = require('ioredis-mock'); | ||
afterEach((done) => { | ||
new Redis().flushall().then(() => done()); | ||
}); | ||
``` | ||
#### `createConnectedClient` is deprecated | ||
Replace it with `.duplicate()` or use another `new Redis` instance. | ||
### Configuring Jest | ||
@@ -57,20 +100,15 @@ | ||
We also support redis publish/subscribe channels (just like ioredis). | ||
Like ioredis, you need two clients: | ||
We also support redis [publish/subscribe](https://redis.io/topics/pubsub) channels. | ||
Like [ioredis](https://github.com/luin/ioredis#pubsub), you need two clients: | ||
- the pubSub client for subcriptions and events, [which can only be used for subscriptions](https://redis.io/topics/pubsub) | ||
- the usual client for issuing 'synchronous' commands like get, publish, etc | ||
```js | ||
const Redis = require('ioredis-mock'); | ||
const redisPub = new Redis(); | ||
const redisSub = new Redis(); | ||
```js | ||
var Redis = require('ioredis-mock'); | ||
var redisPubSub = new Redis(); | ||
// create a second Redis Mock (connected to redisPubSub) | ||
var redisSync = redisPubSub.createConnectedClient(); | ||
redisPubSub.on('message', (channel, message) => { | ||
expect(channel).toBe('emails'); | ||
expect(message).toBe('clark@daily.planet'); | ||
done(); | ||
redisSub.on('message', (channel, message) => { | ||
console.log(`Received ${message} from ${channel}`); | ||
}); | ||
redisPubSub.subscribe('emails'); | ||
redisSync.publish('emails', 'clark@daily.planet'); | ||
redisSub.subscribe('emails'); | ||
redisPub.publish('emails', 'clark@daily.planet'); | ||
``` | ||
@@ -99,3 +137,3 @@ | ||
```js | ||
var Redis = require('ioredis-mock'); | ||
const Redis = require('ioredis-mock'); | ||
const redis = new Redis({ data: { 'k1': 5 } }); | ||
@@ -114,3 +152,3 @@ const commandDefinition: { numberOfKeys: 1, lua: 'return KEYS[1] * ARGV[1]' }; | ||
```js | ||
var Redis = require('ioredis-mock'); | ||
const Redis = require('ioredis-mock'); | ||
const redis = new Redis({ data: { k1: 5 } }); | ||
@@ -135,3 +173,3 @@ const result = redis.eval(`return redis.call("GET", "k1") * 10`); | ||
```js | ||
var Redis = require('ioredis-mock'); | ||
const Redis = require('ioredis-mock'); | ||
@@ -143,23 +181,8 @@ const cluster = new Redis.Cluster(['redis://localhost:7001']); | ||
## Roadmap | ||
## [Roadmap](https://github.com/users/stipsan/projects/1/views/4) | ||
This project started off as just an utility in | ||
[another project](https://github.com/stipsan/epic) and got open sourced to | ||
benefit the rest of the ioredis community. This means there's work to do before | ||
it's feature complete: | ||
You can check the [roadmap project page](https://github.com/users/stipsan/projects/1/views/4), and [the compat table](compat.md), to see how close we are to feature parity with `ioredis`. | ||
- [x] Setup testing suite for the library itself. | ||
- [x] Refactor to bluebird promises like ioredis, support node style callback | ||
too. | ||
- [x] Implement remaining basic features that read/write data. | ||
- [x] Implement ioredis | ||
[argument and reply transformers](https://github.com/luin/ioredis#transforming-arguments--replies). | ||
- [ ] Connection Events | ||
- [ ] Offline Queue | ||
- [x] Pub/Sub | ||
- [ ] Error Handling | ||
- [ ] Implement [remaining](compat.md) commands | ||
## I need a feature not listed here | ||
Just create an issue and tell us all about it or submit a PR with it! 😄 |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
529079
16706
0
182
9