@upstash/redis 0.0.0-ci.c37cc01e → 0.0.0-ci.c6073771-20221014
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/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
- package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
- package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
- package/esm/pkg/commands/scan.js +3 -0
- package/esm/pkg/commands/set.js +16 -4
- package/esm/pkg/commands/zmscore.js +10 -0
- package/esm/pkg/http.js +53 -2
- package/esm/pkg/pipeline.js +23 -5
- package/esm/pkg/redis.js +38 -1
- package/esm/pkg/script.js +77 -0
- package/package.json +1 -39
- package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
- package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
- package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
- package/script/pkg/commands/scan.js +3 -0
- package/script/pkg/commands/set.js +16 -4
- package/script/pkg/commands/zmscore.js +14 -0
- package/script/pkg/http.js +53 -2
- package/script/pkg/pipeline.js +23 -5
- package/script/pkg/redis.js +38 -1
- package/script/pkg/script.js +81 -0
- package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
- package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
- package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
- package/types/pkg/commands/scan.d.ts +1 -0
- package/types/pkg/commands/set.d.ts +31 -2
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/pipeline.d.ts +12 -3
- package/types/pkg/redis.d.ts +17 -1
- package/types/pkg/script.d.ts +42 -0
package/script/pkg/pipeline.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Pipeline = void 0;
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const error_js_1 = require("./error.js");
|
|
6
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
6
7
|
/**
|
|
7
8
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
8
9
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -19,7 +20,7 @@ const error_js_1 = require("./error.js");
|
|
|
19
20
|
* **Examples:**
|
|
20
21
|
*
|
|
21
22
|
* ```ts
|
|
22
|
-
* const p = redis.pipeline()
|
|
23
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
23
24
|
* p.set("key","value")
|
|
24
25
|
* p.get("key")
|
|
25
26
|
* const res = await p.exec()
|
|
@@ -42,7 +43,7 @@ const error_js_1 = require("./error.js");
|
|
|
42
43
|
* ```
|
|
43
44
|
*/
|
|
44
45
|
class Pipeline {
|
|
45
|
-
constructor(
|
|
46
|
+
constructor(opts) {
|
|
46
47
|
Object.defineProperty(this, "client", {
|
|
47
48
|
enumerable: true,
|
|
48
49
|
configurable: true,
|
|
@@ -61,6 +62,12 @@ class Pipeline {
|
|
|
61
62
|
writable: true,
|
|
62
63
|
value: void 0
|
|
63
64
|
});
|
|
65
|
+
Object.defineProperty(this, "multiExec", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
64
71
|
/**
|
|
65
72
|
* Send the pipeline request to upstash.
|
|
66
73
|
*
|
|
@@ -79,8 +86,9 @@ class Pipeline {
|
|
|
79
86
|
if (this.commands.length === 0) {
|
|
80
87
|
throw new Error("Pipeline is empty");
|
|
81
88
|
}
|
|
89
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
82
90
|
const res = (await this.client.request({
|
|
83
|
-
path
|
|
91
|
+
path,
|
|
84
92
|
body: Object.values(this.commands).map((c) => c.command),
|
|
85
93
|
}));
|
|
86
94
|
return res.map(({ error, result }, i) => {
|
|
@@ -1014,6 +1022,15 @@ class Pipeline {
|
|
|
1014
1022
|
writable: true,
|
|
1015
1023
|
value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
|
|
1016
1024
|
});
|
|
1025
|
+
/**
|
|
1026
|
+
* @see https://redis.io/commands/zmscore
|
|
1027
|
+
*/
|
|
1028
|
+
Object.defineProperty(this, "zmscore", {
|
|
1029
|
+
enumerable: true,
|
|
1030
|
+
configurable: true,
|
|
1031
|
+
writable: true,
|
|
1032
|
+
value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
|
|
1033
|
+
});
|
|
1017
1034
|
/**
|
|
1018
1035
|
* @see https://redis.io/commands/zpopmax
|
|
1019
1036
|
*/
|
|
@@ -1122,9 +1139,10 @@ class Pipeline {
|
|
|
1122
1139
|
writable: true,
|
|
1123
1140
|
value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
|
|
1124
1141
|
});
|
|
1125
|
-
this.client = client;
|
|
1142
|
+
this.client = opts.client;
|
|
1126
1143
|
this.commands = [];
|
|
1127
|
-
this.commandOptions = commandOptions;
|
|
1144
|
+
this.commandOptions = opts.commandOptions;
|
|
1145
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1128
1146
|
}
|
|
1129
1147
|
/**
|
|
1130
1148
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/script/pkg/redis.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Redis = void 0;
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const pipeline_js_1 = require("./pipeline.js");
|
|
6
|
+
const script_js_1 = require("./script.js");
|
|
7
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
6
8
|
/**
|
|
7
9
|
* Serverless redis client for upstash.
|
|
8
10
|
*/
|
|
@@ -52,7 +54,30 @@ class Redis {
|
|
|
52
54
|
enumerable: true,
|
|
53
55
|
configurable: true,
|
|
54
56
|
writable: true,
|
|
55
|
-
value: () => new pipeline_js_1.Pipeline(
|
|
57
|
+
value: () => new pipeline_js_1.Pipeline({
|
|
58
|
+
client: this.client,
|
|
59
|
+
commandOptions: this.opts,
|
|
60
|
+
multiExec: false,
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
65
|
+
*
|
|
66
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
67
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
68
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link Pipeline}
|
|
71
|
+
*/
|
|
72
|
+
Object.defineProperty(this, "multi", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: () => new pipeline_js_1.Pipeline({
|
|
77
|
+
client: this.client,
|
|
78
|
+
commandOptions: this.opts,
|
|
79
|
+
multiExec: true,
|
|
80
|
+
})
|
|
56
81
|
});
|
|
57
82
|
/**
|
|
58
83
|
* @see https://redis.io/commands/append
|
|
@@ -977,6 +1002,15 @@ class Redis {
|
|
|
977
1002
|
writable: true,
|
|
978
1003
|
value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
|
|
979
1004
|
});
|
|
1005
|
+
/**
|
|
1006
|
+
* @see https://redis.io/commands/zmscore
|
|
1007
|
+
*/
|
|
1008
|
+
Object.defineProperty(this, "zmscore", {
|
|
1009
|
+
enumerable: true,
|
|
1010
|
+
configurable: true,
|
|
1011
|
+
writable: true,
|
|
1012
|
+
value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
|
|
1013
|
+
});
|
|
980
1014
|
/**
|
|
981
1015
|
* @see https://redis.io/commands/zpopmax
|
|
982
1016
|
*/
|
|
@@ -1088,5 +1122,8 @@ class Redis {
|
|
|
1088
1122
|
this.client = client;
|
|
1089
1123
|
this.opts = opts;
|
|
1090
1124
|
}
|
|
1125
|
+
createScript(script) {
|
|
1126
|
+
return new script_js_1.Script(this, script);
|
|
1127
|
+
}
|
|
1091
1128
|
}
|
|
1092
1129
|
exports.Redis = Redis;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Script = void 0;
|
|
4
|
+
const mod_js_1 = require("../deps/deno.land/x/sha1@v1.0.3/mod.js");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new script.
|
|
7
|
+
*
|
|
8
|
+
* Scripts offer the ability to optimistically try to execute a script without having to send the
|
|
9
|
+
* entire script to the server. If the script is loaded on the server, it tries again by sending
|
|
10
|
+
* the entire script. Afterwards, the script is cached on the server.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const redis = new Redis({...})
|
|
15
|
+
*
|
|
16
|
+
* const script = redis.createScript<string>("return ARGV[1];")
|
|
17
|
+
* const arg1 = await script.eval([], ["Hello World"])
|
|
18
|
+
* assertEquals(arg1, "Hello World")
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class Script {
|
|
22
|
+
constructor(redis, script) {
|
|
23
|
+
Object.defineProperty(this, "script", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "sha1", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "redis", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
this.redis = redis;
|
|
42
|
+
this.sha1 = this.digest(script);
|
|
43
|
+
this.script = script;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Send an `EVAL` command to redis.
|
|
47
|
+
*/
|
|
48
|
+
async eval(keys, args) {
|
|
49
|
+
return await this.redis.eval(this.script, keys, args);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Calculates the sha1 hash of the script and then calls `EVALSHA`.
|
|
53
|
+
*/
|
|
54
|
+
async evalsha(keys, args) {
|
|
55
|
+
return await this.redis.evalsha(this.sha1, keys, args);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Optimistically try to run `EVALSHA` first.
|
|
59
|
+
* If the script is not loaded in redis, it will fall back and try again with `EVAL`.
|
|
60
|
+
*
|
|
61
|
+
* Following calls will be able to use the cached script
|
|
62
|
+
*/
|
|
63
|
+
async exec(keys, args) {
|
|
64
|
+
const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (err) => {
|
|
65
|
+
if (err instanceof Error &&
|
|
66
|
+
err.message.toLowerCase().includes("noscript")) {
|
|
67
|
+
return await this.redis.eval(this.script, keys, args);
|
|
68
|
+
}
|
|
69
|
+
throw err;
|
|
70
|
+
});
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Compute the sha1 hash of the script and return its hex representation.
|
|
75
|
+
*/
|
|
76
|
+
digest(s) {
|
|
77
|
+
const hash = (0, mod_js_1.sha1)(s, "utf8", "hex");
|
|
78
|
+
return typeof hash === "string" ? hash : new TextDecoder().decode(hash);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Script = Script;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const byteLength: (b64: string) => number, toUint8Array: (b64: string) => Uint8Array, fromUint8Array: (buf: Uint8Array) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { encode, decode } from "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Byte length of a SHA1 digest. */
|
|
2
|
+
export declare const BYTES: number;
|
|
3
|
+
/** A class representation of the SHA1 algorithm. */
|
|
4
|
+
export declare class SHA1 {
|
|
5
|
+
readonly hashSize: number;
|
|
6
|
+
private _buf;
|
|
7
|
+
private _bufIdx;
|
|
8
|
+
private _count;
|
|
9
|
+
private _K;
|
|
10
|
+
private _H;
|
|
11
|
+
private _finalized;
|
|
12
|
+
/** Creates a SHA1 instance. */
|
|
13
|
+
constructor();
|
|
14
|
+
/** Reduces the four input numbers to a single one. */
|
|
15
|
+
protected static F(t: number, b: number, c: number, d: number): number;
|
|
16
|
+
/** Initializes a hash instance. */
|
|
17
|
+
init(): SHA1;
|
|
18
|
+
/** Updates a hash with additional message data. */
|
|
19
|
+
update(msg: string | Uint8Array, inputEncoding?: string): SHA1;
|
|
20
|
+
/** Finalizes a hash with additional message data. */
|
|
21
|
+
digest(outputEncoding?: string): string | Uint8Array;
|
|
22
|
+
/** Performs one transformation cycle. */
|
|
23
|
+
private transform;
|
|
24
|
+
}
|
|
25
|
+
/** Generates a SHA1 hash of the input data. */
|
|
26
|
+
export declare function sha1(msg: string | Uint8Array, inputEncoding?: string, outputEncoding?: string): string | Uint8Array;
|
|
@@ -1,13 +1,42 @@
|
|
|
1
1
|
import { Command, CommandOptions } from "./command.js";
|
|
2
|
-
export declare type SetCommandOptions =
|
|
2
|
+
export declare type SetCommandOptions = {
|
|
3
|
+
get: boolean;
|
|
4
|
+
} | ({
|
|
3
5
|
ex: number;
|
|
4
6
|
px?: never;
|
|
7
|
+
exat?: never;
|
|
8
|
+
pxat?: never;
|
|
9
|
+
keepTtl?: never;
|
|
5
10
|
} | {
|
|
6
11
|
ex?: never;
|
|
7
12
|
px: number;
|
|
13
|
+
exat?: never;
|
|
14
|
+
pxat?: never;
|
|
15
|
+
keepTtl?: never;
|
|
8
16
|
} | {
|
|
9
17
|
ex?: never;
|
|
10
18
|
px?: never;
|
|
19
|
+
exat: number;
|
|
20
|
+
pxat?: never;
|
|
21
|
+
keepTtl?: never;
|
|
22
|
+
} | {
|
|
23
|
+
ex?: never;
|
|
24
|
+
px?: never;
|
|
25
|
+
exat?: never;
|
|
26
|
+
pxat: number;
|
|
27
|
+
keepTtl?: never;
|
|
28
|
+
} | {
|
|
29
|
+
ex?: never;
|
|
30
|
+
px?: never;
|
|
31
|
+
exat?: never;
|
|
32
|
+
pxat?: never;
|
|
33
|
+
keepTtl: true;
|
|
34
|
+
} | {
|
|
35
|
+
ex?: never;
|
|
36
|
+
px?: never;
|
|
37
|
+
exat?: never;
|
|
38
|
+
pxat?: never;
|
|
39
|
+
keepTtl?: never;
|
|
11
40
|
}) & ({
|
|
12
41
|
nx: true;
|
|
13
42
|
xx?: never;
|
|
@@ -21,6 +50,6 @@ export declare type SetCommandOptions = ({
|
|
|
21
50
|
/**
|
|
22
51
|
* @see https://redis.io/commands/set
|
|
23
52
|
*/
|
|
24
|
-
export declare class SetCommand<TData, TResult = "OK"> extends Command<TResult, TData> {
|
|
53
|
+
export declare class SetCommand<TData, TResult = TData | "OK" | null> extends Command<TResult, TData | "OK" | null> {
|
|
25
54
|
constructor([key, value, opts]: [key: string, value: TData, opts?: SetCommandOptions], cmdOpts?: CommandOptions<TResult, TData>);
|
|
26
55
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/zmscore
|
|
4
|
+
*/
|
|
5
|
+
export declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] | null> {
|
|
6
|
+
constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
|
|
7
|
+
}
|
package/types/pkg/pipeline.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { CommandArgs } from "./types.js";
|
|
|
18
18
|
* **Examples:**
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
|
-
* const p = redis.pipeline()
|
|
21
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
22
22
|
* p.set("key","value")
|
|
23
23
|
* p.get("key")
|
|
24
24
|
* const res = await p.exec()
|
|
@@ -44,7 +44,12 @@ export declare class Pipeline {
|
|
|
44
44
|
private client;
|
|
45
45
|
private commands;
|
|
46
46
|
private commandOptions?;
|
|
47
|
-
|
|
47
|
+
private multiExec;
|
|
48
|
+
constructor(opts: {
|
|
49
|
+
client: Requester;
|
|
50
|
+
commandOptions?: CommandOptions<any, any>;
|
|
51
|
+
multiExec?: boolean;
|
|
52
|
+
});
|
|
48
53
|
/**
|
|
49
54
|
* Send the pipeline request to upstash.
|
|
50
55
|
*
|
|
@@ -374,7 +379,7 @@ export declare class Pipeline {
|
|
|
374
379
|
/**
|
|
375
380
|
* @see https://redis.io/commands/set
|
|
376
381
|
*/
|
|
377
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
382
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => this;
|
|
378
383
|
/**
|
|
379
384
|
* @see https://redis.io/commands/setbit
|
|
380
385
|
*/
|
|
@@ -483,6 +488,10 @@ export declare class Pipeline {
|
|
|
483
488
|
* @see https://redis.io/commands/zlexcount
|
|
484
489
|
*/
|
|
485
490
|
zlexcount: (key: string, min: string, max: string) => this;
|
|
491
|
+
/**
|
|
492
|
+
* @see https://redis.io/commands/zmscore
|
|
493
|
+
*/
|
|
494
|
+
zmscore: (key: string, members: unknown[]) => this;
|
|
486
495
|
/**
|
|
487
496
|
* @see https://redis.io/commands/zpopmax
|
|
488
497
|
*/
|
package/types/pkg/redis.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CommandOptions, DelCommand, ExistsCommand, FlushAllCommand, MGetCommand
|
|
|
2
2
|
import { Requester, UpstashRequest, UpstashResponse } from "./http.js";
|
|
3
3
|
import { Pipeline } from "./pipeline.js";
|
|
4
4
|
import type { CommandArgs } from "./types.js";
|
|
5
|
+
import { Script } from "./script.js";
|
|
5
6
|
export declare type RedisOptions = {
|
|
6
7
|
/**
|
|
7
8
|
* Automatically try to deserialize the returned data from upstash using `JSON.deserialize`
|
|
@@ -32,12 +33,23 @@ export declare class Redis {
|
|
|
32
33
|
* Wrap a new middleware around the HTTP client.
|
|
33
34
|
*/
|
|
34
35
|
use: <TResult = unknown>(middleware: (r: UpstashRequest, next: <TResult_1 = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult_1>>) => Promise<UpstashResponse<TResult>>) => void;
|
|
36
|
+
createScript(script: string): Script;
|
|
35
37
|
/**
|
|
36
38
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
37
39
|
*
|
|
38
40
|
* @see {@link Pipeline}
|
|
39
41
|
*/
|
|
40
42
|
pipeline: () => Pipeline;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
45
|
+
*
|
|
46
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
47
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
48
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link Pipeline}
|
|
51
|
+
*/
|
|
52
|
+
multi: () => Pipeline;
|
|
41
53
|
/**
|
|
42
54
|
* @see https://redis.io/commands/append
|
|
43
55
|
*/
|
|
@@ -354,7 +366,7 @@ export declare class Redis {
|
|
|
354
366
|
/**
|
|
355
367
|
* @see https://redis.io/commands/set
|
|
356
368
|
*/
|
|
357
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
369
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
|
|
358
370
|
/**
|
|
359
371
|
* @see https://redis.io/commands/setbit
|
|
360
372
|
*/
|
|
@@ -463,6 +475,10 @@ export declare class Redis {
|
|
|
463
475
|
* @see https://redis.io/commands/zlexcount
|
|
464
476
|
*/
|
|
465
477
|
zlexcount: (key: string, min: string, max: string) => Promise<number>;
|
|
478
|
+
/**
|
|
479
|
+
* @see https://redis.io/commands/zmscore
|
|
480
|
+
*/
|
|
481
|
+
zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
|
|
466
482
|
/**
|
|
467
483
|
* @see https://redis.io/commands/zpopmax
|
|
468
484
|
*/
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Redis } from "./redis.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new script.
|
|
4
|
+
*
|
|
5
|
+
* Scripts offer the ability to optimistically try to execute a script without having to send the
|
|
6
|
+
* entire script to the server. If the script is loaded on the server, it tries again by sending
|
|
7
|
+
* the entire script. Afterwards, the script is cached on the server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const redis = new Redis({...})
|
|
12
|
+
*
|
|
13
|
+
* const script = redis.createScript<string>("return ARGV[1];")
|
|
14
|
+
* const arg1 = await script.eval([], ["Hello World"])
|
|
15
|
+
* assertEquals(arg1, "Hello World")
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class Script<TResult = unknown> {
|
|
19
|
+
readonly script: string;
|
|
20
|
+
readonly sha1: string;
|
|
21
|
+
private readonly redis;
|
|
22
|
+
constructor(redis: Redis, script: string);
|
|
23
|
+
/**
|
|
24
|
+
* Send an `EVAL` command to redis.
|
|
25
|
+
*/
|
|
26
|
+
eval(keys: string[], args: string[]): Promise<TResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Calculates the sha1 hash of the script and then calls `EVALSHA`.
|
|
29
|
+
*/
|
|
30
|
+
evalsha(keys: string[], args: string[]): Promise<TResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Optimistically try to run `EVALSHA` first.
|
|
33
|
+
* If the script is not loaded in redis, it will fall back and try again with `EVAL`.
|
|
34
|
+
*
|
|
35
|
+
* Following calls will be able to use the cached script
|
|
36
|
+
*/
|
|
37
|
+
exec(keys: string[], args: string[]): Promise<TResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Compute the sha1 hash of the script and return its hex representation.
|
|
40
|
+
*/
|
|
41
|
+
private digest;
|
|
42
|
+
}
|