Comparing version 4.25.0 to 4.26.0
@@ -7,3 +7,2 @@ "use strict"; | ||
const debug = utils_1.Debug("cluster:subscriber"); | ||
const SUBSCRIBER_CONNECTION_NAME = "ioredisClusterSubscriber"; | ||
class ClusterSubscriber { | ||
@@ -42,2 +41,5 @@ constructor(connectionPool, emitter) { | ||
} | ||
if (this.subscriber) { | ||
this.subscriber.disconnect(); | ||
} | ||
const sampleNode = utils_1.sample(this.connectionPool.getNodes()); | ||
@@ -66,3 +68,3 @@ if (!sampleNode) { | ||
enableReadyCheck: true, | ||
connectionName: SUBSCRIBER_CONNECTION_NAME, | ||
connectionName: util_1.getConnectionName("subscriber", options.connectionName), | ||
lazyConnect: true, | ||
@@ -96,3 +98,6 @@ tls: options.tls, | ||
}) | ||
.catch(utils_1.noop); | ||
.catch(() => { | ||
// TODO: should probably disconnect the subscriber and try again. | ||
debug("failed to %s %d channels", type, channels.length); | ||
}); | ||
} | ||
@@ -99,0 +104,0 @@ } |
@@ -655,3 +655,3 @@ "use strict"; | ||
retryStrategy: null, | ||
connectionName: "ioredisClusterRefresher", | ||
connectionName: util_1.getConnectionName("refresher", this.options.redisOptions && this.options.redisOptions.connectionName), | ||
}); | ||
@@ -658,0 +658,0 @@ // Ignore error events since we will handle |
@@ -95,1 +95,6 @@ "use strict"; | ||
exports.weightSrvRecords = weightSrvRecords; | ||
function getConnectionName(component, nodeConnectionName) { | ||
const prefix = `ioredis-cluster(${component})`; | ||
return nodeConnectionName ? `${prefix}:${nodeConnectionName}` : prefix; | ||
} | ||
exports.getConnectionName = getConnectionName; |
@@ -0,1 +1,13 @@ | ||
# [4.26.0](https://github.com/luin/ioredis/compare/v4.25.0...v4.26.0) (2021-04-08) | ||
### Bug Fixes | ||
* **cluster:** subscriber connection leaks ([81b9be0](https://github.com/luin/ioredis/commit/81b9be021d471796bba00ee7b08768df9d7e2689)), closes [#1325](https://github.com/luin/ioredis/issues/1325) | ||
### Features | ||
* **cluster:** apply provided connection name to internal connections ([2e388db](https://github.com/luin/ioredis/commit/2e388dbaa528d009b97b82c4dc362377165670a4)) | ||
# [4.25.0](https://github.com/luin/ioredis/compare/v4.24.6...v4.25.0) (2021-04-02) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "ioredis", | ||
"version": "4.25.0", | ||
"version": "4.26.0", | ||
"description": "A robust, performance-focused and full-featured Redis client for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "built/index.js", |
@@ -14,3 +14,3 @@ [![ioredis](https://cdn.jsdelivr.net/gh/luin/ioredis@b5e8c74/logo.svg)](https://github.com/luin/ioredis) | ||
Supports Redis >= 2.6.12 and (Node.js >= 6). | ||
Supports Redis >= 2.6.12 and (Node.js >= 6). Completely compatible with Redis 6.x. | ||
@@ -210,3 +210,3 @@ # Features | ||
```javascript | ||
const Redis = require('ioredis'); | ||
const Redis = require("ioredis"); | ||
const sub = new Redis(); | ||
@@ -216,3 +216,3 @@ const pub = new Redis(); | ||
sub.subscribe(/* ... */); // From now, `sub` enters the subscriber mode. | ||
sub.on("message", /* ... */); | ||
sub.on("message" /* ... */); | ||
@@ -236,2 +236,30 @@ setInterval(() => { | ||
## Streams | ||
Redis v5 introduces a new data type called streams. It doubles as a communication channel for building streaming architectures and as a log-like data structure for persisting data. With ioredis, the usage can be pretty straightforward. Say we have a producer publishes messages to a stream with `redis.xadd("mystream", "*", "randomValue", Math.random())` (You may find the [official documentation of Streams](https://redis.io/topics/streams-intro) as a starter to understand the parameters used), to consume the messages, we'll have a consumer with the following code: | ||
```javascript | ||
const Redis = require("ioredis"); | ||
const redis = new Redis(); | ||
const processMessage = (message) => { | ||
console.log("Id: %s. Data: %O", message[0], message[1]); | ||
}; | ||
async function listenForMessage(lastId = "$") { | ||
// `results` is an array, each element of which corresponds to a key. | ||
// Because we only listen to one key (mystream) here, `results` only contains | ||
// a single element. See more: https://redis.io/commands/xread#return-value | ||
const results = await redis.xread("block", 0, "STREAMS", "mystream", lastId); | ||
const [key, messages] = results[0]; // `key` equals to "mystream" | ||
messages.forEach(processMessage); | ||
// Pass the last id of the results to the next round. | ||
await listenForMessage(messages[messages.length - 1][0]); | ||
} | ||
listenForMessage(); | ||
``` | ||
## Handle Binary Data | ||
@@ -748,3 +776,3 @@ | ||
| end | emits after `close` when no more reconnections will be made, or the connection is failed to establish. | | ||
| wait | emits when `lazyConnect` is set and will wait for the first command to be called before connecting. | | ||
| wait | emits when `lazyConnect` is set and will wait for the first command to be called before connecting. | | ||
@@ -751,0 +779,0 @@ You can also check out the `Redis#status` property to get the current connection status. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281903
4673
1351