Comparing version 5.4.2 to 5.5.0
@@ -8,3 +8,7 @@ /// <reference types="node" /> | ||
export declare type DNSLookupFunction = (hostname: string, callback: (err: NodeJS.ErrnoException | null | undefined, address: string, family?: number) => void) => void; | ||
export interface NatMap { | ||
export declare type NatMapFunction = (key: string) => { | ||
host: string; | ||
port: number; | ||
} | null; | ||
export declare type NatMap = { | ||
[key: string]: { | ||
@@ -14,3 +18,3 @@ host: string; | ||
}; | ||
} | ||
} | NatMapFunction; | ||
/** | ||
@@ -17,0 +21,0 @@ * Options for Cluster constructor |
@@ -631,12 +631,16 @@ "use strict"; | ||
natMapper(nodeKey) { | ||
if (this.options.natMap && typeof this.options.natMap === "object") { | ||
const key = typeof nodeKey === "string" | ||
? nodeKey | ||
: `${nodeKey.host}:${nodeKey.port}`; | ||
const mapped = this.options.natMap[key]; | ||
if (mapped) { | ||
debug("NAT mapping %s -> %O", key, mapped); | ||
return Object.assign({}, mapped); | ||
} | ||
const key = typeof nodeKey === "string" | ||
? nodeKey | ||
: `${nodeKey.host}:${nodeKey.port}`; | ||
let mapped = null; | ||
if (this.options.natMap && typeof this.options.natMap === "function") { | ||
mapped = this.options.natMap(key); | ||
} | ||
else if (this.options.natMap && typeof this.options.natMap === "object") { | ||
mapped = this.options.natMap[key]; | ||
} | ||
if (mapped) { | ||
debug("NAT mapping %s -> %O", key, mapped); | ||
return Object.assign({}, mapped); | ||
} | ||
return typeof nodeKey === "string" | ||
@@ -643,0 +647,0 @@ ? (0, util_1.nodeKeyToRedisOptions)(nodeKey) |
@@ -165,3 +165,11 @@ "use strict"; | ||
return item; | ||
return this.options.natMap[`${item.host}:${item.port}`] || item; | ||
const key = `${item.host}:${item.port}`; | ||
let result = item; | ||
if (typeof this.options.natMap === "function") { | ||
result = this.options.natMap(key) || item; | ||
} | ||
else if (typeof this.options.natMap === "object") { | ||
result = this.options.natMap[key] || item; | ||
} | ||
return result; | ||
} | ||
@@ -168,0 +176,0 @@ connectToSentinel(endpoint, options) { |
@@ -10,2 +10,3 @@ /// <reference types="node" /> | ||
count?: string | number; | ||
noValues?: boolean; | ||
} | ||
@@ -12,0 +13,0 @@ /** |
@@ -32,2 +32,5 @@ "use strict"; | ||
} | ||
if (this.opt.noValues) { | ||
args.push("NOVALUES"); | ||
} | ||
this.opt.redis[this.opt.command](args, (err, res) => { | ||
@@ -34,0 +37,0 @@ if (err) { |
@@ -32,2 +32,3 @@ /// <reference types="node" /> | ||
count?: number; | ||
noValues?: boolean; | ||
} |
{ | ||
"name": "ioredis", | ||
"version": "5.4.2", | ||
"version": "5.5.0", | ||
"description": "A robust, performance-focused and full-featured Redis client for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "./built/index.js", |
@@ -17,2 +17,4 @@ [![ioredis](https://cdn.jsdelivr.net/gh/redis/ioredis@b5e8c74/logo.svg)](https://github.com/redis/ioredis) | ||
ioredis is a stable project and maintenance is done on a best-effort basis for relevant issues (contributions to ioredis will still be evaluated, reviewed, and merged when they benefit the project). For new projects, node-redis is the recommended client library. [node-redis](https://github.com/redis/node-redis) is the open-source (MIT license) Redis JavaScript client library redesigned from the ground up and actively maintained. [node-redis](https://github.com/redis/node-redis) supports new (hash-field expiration) and future commands and the capabilities available in Redis Stack and Redis 8 (search, JSON, time-series, probabilistic data structures). | ||
# Features | ||
@@ -727,7 +729,13 @@ | ||
```javascript | ||
const stream = redis.zscanStream("myhash", { | ||
match: "age:??", | ||
}); | ||
``` | ||
The `hscanStream` also accepts the `noValues` option to specify whether Redis should return only the keys in the hash table without their corresponding values. | ||
```javascript | ||
const stream = redis.hscanStream("myhash", { | ||
match: "age:??", | ||
noValues: true, | ||
}); | ||
``` | ||
You can learn more from the [Redis documentation](http://redis.io/commands/scan). | ||
@@ -1135,4 +1143,28 @@ | ||
Or you can specify this parameter through function: | ||
```javascript | ||
const cluster = new Redis.Cluster( | ||
[ | ||
{ | ||
host: "203.0.113.73", | ||
port: 30001, | ||
}, | ||
], | ||
{ | ||
natMap: (key) => { | ||
if(key.indexOf('30001')) { | ||
return { host: "203.0.113.73", port: 30001 }; | ||
} | ||
return null; | ||
}, | ||
} | ||
); | ||
``` | ||
This option is also useful when the cluster is running inside a Docker container. | ||
Also it works for Clusters in cloud infrastructure where cluster nodes connected through dedicated subnet. | ||
Specifying through may be useful if you don't know concrete internal host and know only node port. | ||
### Transaction and Pipeline in Cluster Mode | ||
@@ -1139,0 +1171,0 @@ |
700079
15179
1447