@upstash/redis 1.14.0 → 1.15.0-next.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/esm/pkg/pipeline.js +13 -5
- package/esm/pkg/redis.js +24 -1
- package/package.json +2 -2
- package/script/pkg/pipeline.js +13 -5
- package/script/pkg/redis.js +24 -1
- package/types/pkg/pipeline.d.ts +7 -2
- package/types/pkg/redis.d.ts +10 -0
package/esm/pkg/pipeline.js
CHANGED
|
@@ -17,7 +17,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
|
17
17
|
* **Examples:**
|
|
18
18
|
*
|
|
19
19
|
* ```ts
|
|
20
|
-
* const p = redis.pipeline()
|
|
20
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
21
21
|
* p.set("key","value")
|
|
22
22
|
* p.get("key")
|
|
23
23
|
* const res = await p.exec()
|
|
@@ -40,7 +40,7 @@ import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export class Pipeline {
|
|
43
|
-
constructor(
|
|
43
|
+
constructor(opts) {
|
|
44
44
|
Object.defineProperty(this, "client", {
|
|
45
45
|
enumerable: true,
|
|
46
46
|
configurable: true,
|
|
@@ -59,6 +59,12 @@ export class Pipeline {
|
|
|
59
59
|
writable: true,
|
|
60
60
|
value: void 0
|
|
61
61
|
});
|
|
62
|
+
Object.defineProperty(this, "multiExec", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
62
68
|
/**
|
|
63
69
|
* Send the pipeline request to upstash.
|
|
64
70
|
*
|
|
@@ -77,8 +83,9 @@ export class Pipeline {
|
|
|
77
83
|
if (this.commands.length === 0) {
|
|
78
84
|
throw new Error("Pipeline is empty");
|
|
79
85
|
}
|
|
86
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
80
87
|
const res = (await this.client.request({
|
|
81
|
-
path
|
|
88
|
+
path,
|
|
82
89
|
body: Object.values(this.commands).map((c) => c.command),
|
|
83
90
|
}));
|
|
84
91
|
return res.map(({ error, result }, i) => {
|
|
@@ -1129,9 +1136,10 @@ export class Pipeline {
|
|
|
1129
1136
|
writable: true,
|
|
1130
1137
|
value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
|
|
1131
1138
|
});
|
|
1132
|
-
this.client = client;
|
|
1139
|
+
this.client = opts.client;
|
|
1133
1140
|
this.commands = [];
|
|
1134
|
-
this.commandOptions = commandOptions;
|
|
1141
|
+
this.commandOptions = opts.commandOptions;
|
|
1142
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1135
1143
|
}
|
|
1136
1144
|
/**
|
|
1137
1145
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/esm/pkg/redis.js
CHANGED
|
@@ -51,7 +51,30 @@ export class Redis {
|
|
|
51
51
|
enumerable: true,
|
|
52
52
|
configurable: true,
|
|
53
53
|
writable: true,
|
|
54
|
-
value: () => new Pipeline(
|
|
54
|
+
value: () => new Pipeline({
|
|
55
|
+
client: this.client,
|
|
56
|
+
commandOptions: this.opts,
|
|
57
|
+
multiExec: false,
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
62
|
+
*
|
|
63
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
64
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
65
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link Pipeline}
|
|
68
|
+
*/
|
|
69
|
+
Object.defineProperty(this, "multi", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: () => new Pipeline({
|
|
74
|
+
client: this.client,
|
|
75
|
+
commandOptions: this.opts,
|
|
76
|
+
multiExec: true,
|
|
77
|
+
})
|
|
55
78
|
});
|
|
56
79
|
/**
|
|
57
80
|
* @see https://redis.io/commands/append
|
package/package.json
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"main": "./script/platforms/nodejs.js",
|
|
4
4
|
"types": "./types/platforms/nodejs.d.ts",
|
|
5
5
|
"name": "@upstash/redis",
|
|
6
|
-
"version": "v1.14.0",
|
|
7
6
|
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
|
|
8
7
|
"repository": {
|
|
9
8
|
"type": "git",
|
|
@@ -59,5 +58,6 @@
|
|
|
59
58
|
"require": "./script/platforms/node_with_fetch.js",
|
|
60
59
|
"types": "./types/platforms/node_with_fetch.d.ts"
|
|
61
60
|
}
|
|
62
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"version": "1.15.0-next.1"
|
|
63
63
|
}
|
package/script/pkg/pipeline.js
CHANGED
|
@@ -20,7 +20,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
|
|
|
20
20
|
* **Examples:**
|
|
21
21
|
*
|
|
22
22
|
* ```ts
|
|
23
|
-
* const p = redis.pipeline()
|
|
23
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
24
24
|
* p.set("key","value")
|
|
25
25
|
* p.get("key")
|
|
26
26
|
* const res = await p.exec()
|
|
@@ -43,7 +43,7 @@ const zmscore_js_1 = require("./commands/zmscore.js");
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
class Pipeline {
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(opts) {
|
|
47
47
|
Object.defineProperty(this, "client", {
|
|
48
48
|
enumerable: true,
|
|
49
49
|
configurable: true,
|
|
@@ -62,6 +62,12 @@ class Pipeline {
|
|
|
62
62
|
writable: true,
|
|
63
63
|
value: void 0
|
|
64
64
|
});
|
|
65
|
+
Object.defineProperty(this, "multiExec", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
65
71
|
/**
|
|
66
72
|
* Send the pipeline request to upstash.
|
|
67
73
|
*
|
|
@@ -80,8 +86,9 @@ class Pipeline {
|
|
|
80
86
|
if (this.commands.length === 0) {
|
|
81
87
|
throw new Error("Pipeline is empty");
|
|
82
88
|
}
|
|
89
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
83
90
|
const res = (await this.client.request({
|
|
84
|
-
path
|
|
91
|
+
path,
|
|
85
92
|
body: Object.values(this.commands).map((c) => c.command),
|
|
86
93
|
}));
|
|
87
94
|
return res.map(({ error, result }, i) => {
|
|
@@ -1132,9 +1139,10 @@ class Pipeline {
|
|
|
1132
1139
|
writable: true,
|
|
1133
1140
|
value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
|
|
1134
1141
|
});
|
|
1135
|
-
this.client = client;
|
|
1142
|
+
this.client = opts.client;
|
|
1136
1143
|
this.commands = [];
|
|
1137
|
-
this.commandOptions = commandOptions;
|
|
1144
|
+
this.commandOptions = opts.commandOptions;
|
|
1145
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1138
1146
|
}
|
|
1139
1147
|
/**
|
|
1140
1148
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/script/pkg/redis.js
CHANGED
|
@@ -54,7 +54,30 @@ class Redis {
|
|
|
54
54
|
enumerable: true,
|
|
55
55
|
configurable: true,
|
|
56
56
|
writable: true,
|
|
57
|
-
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
|
+
})
|
|
58
81
|
});
|
|
59
82
|
/**
|
|
60
83
|
* @see https://redis.io/commands/append
|
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
|
*
|
package/types/pkg/redis.d.ts
CHANGED
|
@@ -40,6 +40,16 @@ export declare class Redis {
|
|
|
40
40
|
* @see {@link Pipeline}
|
|
41
41
|
*/
|
|
42
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;
|
|
43
53
|
/**
|
|
44
54
|
* @see https://redis.io/commands/append
|
|
45
55
|
*/
|