falkordb 7.0.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/falkordb.js
CHANGED
|
@@ -13,6 +13,8 @@ const single_1 = require("./clients/single");
|
|
|
13
13
|
const sentinel_1 = require("./clients/sentinel");
|
|
14
14
|
const cluster_1 = require("./clients/cluster");
|
|
15
15
|
const nullClient_1 = require("./clients/nullClient");
|
|
16
|
+
const server_mode_1 = require("./server-mode");
|
|
17
|
+
const replication_role_1 = require("./replication-role");
|
|
16
18
|
/**
|
|
17
19
|
* Retries the initial connection gets before `FalkorDB.connect()` rejects.
|
|
18
20
|
*/
|
|
@@ -39,15 +41,15 @@ function initialReconnectStrategy(retries, cause, tlsEnabled) {
|
|
|
39
41
|
return new Error(`Failed to connect to FalkorDB: ${cause.message}.${hint}`, { cause });
|
|
40
42
|
}
|
|
41
43
|
async function clientFactory(client, sentinelOptions) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
+
const mode = (0, server_mode_1.serverMode)(await client.info("server"));
|
|
45
|
+
if (mode === "sentinel") {
|
|
44
46
|
return new sentinel_1.Sentinel(client, sentinelOptions);
|
|
45
47
|
}
|
|
46
|
-
else if (
|
|
48
|
+
else if (mode === "cluster") {
|
|
47
49
|
// Connecting through a replica (or asking for `readonly`) opts in to
|
|
48
50
|
// serving read-only commands from replicas, see `Cluster`.
|
|
49
51
|
const replication = await client.info("replication");
|
|
50
|
-
const useReplicas = client.options?.readonly === true ||
|
|
52
|
+
const useReplicas = client.options?.readonly === true || (0, replication_role_1.isReplica)(replication);
|
|
51
53
|
return new cluster_1.Cluster(client, { useReplicas });
|
|
52
54
|
}
|
|
53
55
|
return new single_1.Single(client);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReplica = isReplica;
|
|
4
|
+
// Redis and Valkey both report `role:slave` today; `replica` is the name both
|
|
5
|
+
// use everywhere else (REPLICAOF, `replica-*` settings), so accept it too.
|
|
6
|
+
const ROLE_FIELD = /^role:([^\r\n]*)\r?$/m;
|
|
7
|
+
const REPLICA_ROLES = new Set(['slave', 'replica']);
|
|
8
|
+
/**
|
|
9
|
+
* Reads the `role` field of an `INFO replication` reply and says whether the
|
|
10
|
+
* server is a replica. A reply without a role is not a replica.
|
|
11
|
+
*/
|
|
12
|
+
function isReplica(info) {
|
|
13
|
+
const role = ROLE_FIELD.exec(info)?.[1].trim();
|
|
14
|
+
return role !== undefined && REPLICA_ROLES.has(role);
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a server says it runs in its `INFO server` reply: `standalone`,
|
|
3
|
+
* `sentinel` or `cluster`.
|
|
4
|
+
*/
|
|
5
|
+
export type ServerMode = 'standalone' | 'sentinel' | 'cluster';
|
|
6
|
+
/**
|
|
7
|
+
* Reads the mode from an `INFO server` reply. A server that does not report a
|
|
8
|
+
* mode we know of is treated as standalone.
|
|
9
|
+
*/
|
|
10
|
+
export declare function serverMode(info: string): ServerMode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serverMode = serverMode;
|
|
4
|
+
// Redis names the field `redis_mode`. Valkey names it `server_mode`, unless
|
|
5
|
+
// `extended-redis-compatibility` is on, and FalkorDB images ship either one.
|
|
6
|
+
const MODE_FIELD = /^(?:redis|server)_mode:([^\r\n]*)\r?$/m;
|
|
7
|
+
/**
|
|
8
|
+
* Reads the mode from an `INFO server` reply. A server that does not report a
|
|
9
|
+
* mode we know of is treated as standalone.
|
|
10
|
+
*/
|
|
11
|
+
function serverMode(info) {
|
|
12
|
+
const mode = MODE_FIELD.exec(info)?.[1].trim();
|
|
13
|
+
return mode === 'sentinel' || mode === 'cluster' ? mode : 'standalone';
|
|
14
|
+
}
|