@upstash/redis 0.0.0-ci.b1b216d3-20230414 → 0.0.0-ci.b3f07153-20231018
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/commands/geo_add.js +27 -0
- package/esm/pkg/commands/geo_dist.js +11 -0
- package/esm/pkg/commands/hgetall.js +9 -1
- package/esm/pkg/commands/mod.js +5 -0
- package/esm/pkg/commands/set.js +1 -1
- package/esm/pkg/commands/xadd.js +26 -0
- package/esm/pkg/commands/xrange.js +36 -0
- package/esm/pkg/commands/zunion.js +30 -0
- package/esm/pkg/http.js +16 -9
- package/esm/pkg/pipeline.js +32 -8
- package/esm/pkg/redis.js +36 -1
- package/esm/platforms/nodejs.js +4 -2
- package/esm/version.js +1 -1
- package/package.json +13 -5
- package/script/pkg/commands/geo_add.js +31 -0
- package/script/pkg/commands/geo_dist.js +15 -0
- package/script/pkg/commands/hgetall.js +9 -1
- package/script/pkg/commands/mod.js +5 -0
- package/script/pkg/commands/set.js +1 -1
- package/script/pkg/commands/xadd.js +30 -0
- package/script/pkg/commands/xrange.js +40 -0
- package/script/pkg/commands/zunion.js +34 -0
- package/script/pkg/http.js +16 -9
- package/script/pkg/pipeline.js +31 -7
- package/script/pkg/redis.js +35 -0
- package/script/platforms/nodejs.js +4 -2
- package/script/version.js +1 -1
- package/types/pkg/commands/geo_add.d.ts +25 -0
- package/types/pkg/commands/geo_dist.d.ts +12 -0
- package/types/pkg/commands/hdel.d.ts +1 -1
- package/types/pkg/commands/mod.d.ts +5 -0
- package/types/pkg/commands/set.d.ts +2 -2
- package/types/pkg/commands/xadd.d.ts +31 -0
- package/types/pkg/commands/xrange.d.ts +9 -0
- package/types/pkg/commands/zunion.d.ts +29 -0
- package/types/pkg/http.d.ts +5 -1
- package/types/pkg/pipeline.d.ts +241 -150
- package/types/pkg/redis.d.ts +42 -4
- package/types/version.d.ts +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/geoadd
|
|
4
|
+
*/
|
|
5
|
+
export class GeoAddCommand extends Command {
|
|
6
|
+
constructor([key, arg1, ...arg2], opts) {
|
|
7
|
+
const command = ["geoadd", key];
|
|
8
|
+
if ("nx" in arg1 && arg1.nx) {
|
|
9
|
+
command.push("nx");
|
|
10
|
+
}
|
|
11
|
+
else if ("xx" in arg1 && arg1.xx) {
|
|
12
|
+
command.push("xx");
|
|
13
|
+
}
|
|
14
|
+
if ("ch" in arg1 && arg1.ch) {
|
|
15
|
+
command.push("ch");
|
|
16
|
+
}
|
|
17
|
+
if ("latitude" in arg1 && arg1.latitude) {
|
|
18
|
+
command.push(arg1.longitude, arg1.latitude, arg1.member);
|
|
19
|
+
}
|
|
20
|
+
command.push(...arg2.flatMap(({ latitude, longitude, member }) => [
|
|
21
|
+
longitude,
|
|
22
|
+
latitude,
|
|
23
|
+
member,
|
|
24
|
+
]));
|
|
25
|
+
super(command, opts);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/geodist
|
|
4
|
+
*/
|
|
5
|
+
export class GeoDistCommand extends Command {
|
|
6
|
+
constructor([key, member1, member2, unit = "M"], opts) {
|
|
7
|
+
const command = ["GEODIST", key];
|
|
8
|
+
command.push(member1, member2, unit);
|
|
9
|
+
super(command, opts);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -8,7 +8,15 @@ function deserialize(result) {
|
|
|
8
8
|
const key = result.shift();
|
|
9
9
|
const value = result.shift();
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
// handle unsafe integer
|
|
12
|
+
const valueIsNumberAndNotSafeInteger = !isNaN(Number(value)) &&
|
|
13
|
+
!Number.isSafeInteger(value);
|
|
14
|
+
if (valueIsNumberAndNotSafeInteger) {
|
|
15
|
+
obj[key] = value;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
obj[key] = JSON.parse(value);
|
|
19
|
+
}
|
|
12
20
|
}
|
|
13
21
|
catch {
|
|
14
22
|
obj[key] = value;
|
package/esm/pkg/commands/mod.js
CHANGED
|
@@ -15,6 +15,8 @@ export * from "./expire.js";
|
|
|
15
15
|
export * from "./expireat.js";
|
|
16
16
|
export * from "./flushall.js";
|
|
17
17
|
export * from "./flushdb.js";
|
|
18
|
+
export * from "./geo_add.js";
|
|
19
|
+
export * from "./geo_dist.js";
|
|
18
20
|
export * from "./get.js";
|
|
19
21
|
export * from "./getbit.js";
|
|
20
22
|
export * from "./getdel.js";
|
|
@@ -137,4 +139,7 @@ export * from "./zremrangebyscore.js";
|
|
|
137
139
|
export * from "./zrevrank.js";
|
|
138
140
|
export * from "./zscan.js";
|
|
139
141
|
export * from "./zscore.js";
|
|
142
|
+
export * from "./zunion.js";
|
|
140
143
|
export * from "./zunionstore.js";
|
|
144
|
+
export * from "./xadd.js";
|
|
145
|
+
export * from "./xrange.js";
|
package/esm/pkg/commands/set.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/xadd
|
|
4
|
+
*/
|
|
5
|
+
export class XAddCommand extends Command {
|
|
6
|
+
constructor([key, id, entries, opts], commandOptions) {
|
|
7
|
+
const command = ["XADD", key];
|
|
8
|
+
if (opts) {
|
|
9
|
+
if (opts.nomkStream) {
|
|
10
|
+
command.push("NOMKSTREAM");
|
|
11
|
+
}
|
|
12
|
+
if (opts.trim) {
|
|
13
|
+
command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
|
|
14
|
+
if (typeof opts.trim.limit !== "undefined") {
|
|
15
|
+
command.push("LIMIT", opts.trim.limit);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
command.push(id);
|
|
20
|
+
// entries
|
|
21
|
+
Object.entries(entries).forEach(([k, v]) => {
|
|
22
|
+
command.push(k, v);
|
|
23
|
+
});
|
|
24
|
+
super(command, commandOptions);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
function deserialize(result) {
|
|
3
|
+
const obj = {};
|
|
4
|
+
for (const e of result) {
|
|
5
|
+
while (e.length >= 2) {
|
|
6
|
+
const streamId = e.shift();
|
|
7
|
+
const entries = e.shift();
|
|
8
|
+
if (!(streamId in obj)) {
|
|
9
|
+
obj[streamId] = {};
|
|
10
|
+
}
|
|
11
|
+
while (entries.length >= 2) {
|
|
12
|
+
const field = entries.shift();
|
|
13
|
+
const value = entries.shift();
|
|
14
|
+
try {
|
|
15
|
+
obj[streamId][field] = JSON.parse(value);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
obj[streamId][field] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
export class XRangeCommand extends Command {
|
|
26
|
+
constructor([key, start, end, count], opts) {
|
|
27
|
+
const command = ["XRANGE", key, start, end];
|
|
28
|
+
if (typeof count === "number") {
|
|
29
|
+
command.push("COUNT", count);
|
|
30
|
+
}
|
|
31
|
+
super(command, {
|
|
32
|
+
deserialize: (result) => deserialize(result),
|
|
33
|
+
...opts,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/zunion
|
|
4
|
+
*/
|
|
5
|
+
export class ZUnionCommand extends Command {
|
|
6
|
+
constructor([numKeys, keyOrKeys, opts], cmdOpts) {
|
|
7
|
+
const command = ["zunion", numKeys];
|
|
8
|
+
if (Array.isArray(keyOrKeys)) {
|
|
9
|
+
command.push(...keyOrKeys);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
command.push(keyOrKeys);
|
|
13
|
+
}
|
|
14
|
+
if (opts) {
|
|
15
|
+
if ("weights" in opts && opts.weights) {
|
|
16
|
+
command.push("weights", ...opts.weights);
|
|
17
|
+
}
|
|
18
|
+
else if ("weight" in opts && typeof opts.weight === "number") {
|
|
19
|
+
command.push("weights", opts.weight);
|
|
20
|
+
}
|
|
21
|
+
if ("aggregate" in opts) {
|
|
22
|
+
command.push("aggregate", opts.aggregate);
|
|
23
|
+
}
|
|
24
|
+
if (opts?.withScores) {
|
|
25
|
+
command.push("withscores");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
super(command, cmdOpts);
|
|
29
|
+
}
|
|
30
|
+
}
|
package/esm/pkg/http.js
CHANGED
|
@@ -100,10 +100,17 @@ export class HttpClient {
|
|
|
100
100
|
}
|
|
101
101
|
const body = (await res.json());
|
|
102
102
|
if (!res.ok) {
|
|
103
|
-
throw new UpstashError(body.error);
|
|
103
|
+
throw new UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`);
|
|
104
104
|
}
|
|
105
105
|
if (this.options?.responseEncoding === "base64") {
|
|
106
|
-
|
|
106
|
+
if (Array.isArray(body)) {
|
|
107
|
+
return body.map(({ result, error }) => ({
|
|
108
|
+
result: decode(result),
|
|
109
|
+
error,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
const result = decode(body.result);
|
|
113
|
+
return { result, error: body.error };
|
|
107
114
|
}
|
|
108
115
|
return body;
|
|
109
116
|
}
|
|
@@ -134,19 +141,19 @@ function base64decode(b64) {
|
|
|
134
141
|
}
|
|
135
142
|
function decode(raw) {
|
|
136
143
|
let result = undefined;
|
|
137
|
-
switch (typeof raw
|
|
144
|
+
switch (typeof raw) {
|
|
138
145
|
case "undefined":
|
|
139
146
|
return raw;
|
|
140
147
|
case "number": {
|
|
141
|
-
result = raw
|
|
148
|
+
result = raw;
|
|
142
149
|
break;
|
|
143
150
|
}
|
|
144
151
|
case "object": {
|
|
145
|
-
if (Array.isArray(raw
|
|
146
|
-
result = raw.
|
|
152
|
+
if (Array.isArray(raw)) {
|
|
153
|
+
result = raw.map((v) => typeof v === "string"
|
|
147
154
|
? base64decode(v)
|
|
148
155
|
: Array.isArray(v)
|
|
149
|
-
? v.map(
|
|
156
|
+
? v.map(decode)
|
|
150
157
|
: v);
|
|
151
158
|
}
|
|
152
159
|
else {
|
|
@@ -157,11 +164,11 @@ function decode(raw) {
|
|
|
157
164
|
break;
|
|
158
165
|
}
|
|
159
166
|
case "string": {
|
|
160
|
-
result = raw
|
|
167
|
+
result = raw === "OK" ? "OK" : base64decode(raw);
|
|
161
168
|
break;
|
|
162
169
|
}
|
|
163
170
|
default:
|
|
164
171
|
break;
|
|
165
172
|
}
|
|
166
|
-
return
|
|
173
|
+
return result;
|
|
167
174
|
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
1
|
+
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GeoAddCommand, GeoDistCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { UpstashError } from "./error.js";
|
|
3
3
|
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
4
4
|
import { HRandFieldCommand } from "./commands/hrandfield.js";
|
|
@@ -31,7 +31,7 @@ import { ZDiffStoreCommand } from "./commands/zdiffstore.js";
|
|
|
31
31
|
* const res = await p.set("key","value").get("key").exec()
|
|
32
32
|
* ```
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* Return types are inferred if all commands are chained, but you can still
|
|
35
35
|
* override the response type manually:
|
|
36
36
|
* ```ts
|
|
37
37
|
* redis.pipeline()
|
|
@@ -72,9 +72,11 @@ export class Pipeline {
|
|
|
72
72
|
*
|
|
73
73
|
* Returns an array with the results of all pipelined commands.
|
|
74
74
|
*
|
|
75
|
-
* You can define a return type manually
|
|
75
|
+
* If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:
|
|
76
76
|
* ```ts
|
|
77
|
-
* redis.pipeline()
|
|
77
|
+
* const p = redis.pipeline()
|
|
78
|
+
* p.get("key")
|
|
79
|
+
* const result = p.exec<[{ greeting: string }]>()
|
|
78
80
|
* ```
|
|
79
81
|
*/
|
|
80
82
|
Object.defineProperty(this, "exec", {
|
|
@@ -1183,24 +1185,38 @@ export class Pipeline {
|
|
|
1183
1185
|
writable: true,
|
|
1184
1186
|
value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
|
|
1185
1187
|
});
|
|
1188
|
+
/**
|
|
1189
|
+
* @see https://redis.io/commands/zunion
|
|
1190
|
+
*/
|
|
1191
|
+
Object.defineProperty(this, "zunion", {
|
|
1192
|
+
enumerable: true,
|
|
1193
|
+
configurable: true,
|
|
1194
|
+
writable: true,
|
|
1195
|
+
value: (...args) => this.chain(new ZUnionCommand(args, this.commandOptions))
|
|
1196
|
+
});
|
|
1186
1197
|
this.client = opts.client;
|
|
1187
|
-
this.commands = [];
|
|
1198
|
+
this.commands = []; // the TCommands generic in the class definition is only used for carrying through chained command types and should never be explicitly set when instantiating the class
|
|
1188
1199
|
this.commandOptions = opts.commandOptions;
|
|
1189
1200
|
this.multiExec = opts.multiExec ?? false;
|
|
1190
1201
|
}
|
|
1191
1202
|
/**
|
|
1192
|
-
*
|
|
1203
|
+
* Returns the length of pipeline before the execution
|
|
1204
|
+
*/
|
|
1205
|
+
length() {
|
|
1206
|
+
return this.commands.length;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Pushes a command into the pipeline and returns a chainable instance of the
|
|
1193
1210
|
* pipeline
|
|
1194
1211
|
*/
|
|
1195
1212
|
chain(command) {
|
|
1196
1213
|
this.commands.push(command);
|
|
1197
|
-
return this;
|
|
1214
|
+
return this; // TS thinks we're returning Pipeline<[]> here, because we're not creating a new instance of the class, hence the cast
|
|
1198
1215
|
}
|
|
1199
1216
|
/**
|
|
1200
1217
|
* @see https://redis.io/commands/?group=json
|
|
1201
1218
|
*/
|
|
1202
1219
|
get json() {
|
|
1203
|
-
// For some reason we needed to define the types manually, otherwise Deno wouldn't build it
|
|
1204
1220
|
return {
|
|
1205
1221
|
/**
|
|
1206
1222
|
* @see https://redis.io/commands/json.arrappend
|
|
@@ -1238,6 +1254,14 @@ export class Pipeline {
|
|
|
1238
1254
|
* @see https://redis.io/commands/json.forget
|
|
1239
1255
|
*/
|
|
1240
1256
|
forget: (...args) => this.chain(new JsonForgetCommand(args, this.commandOptions)),
|
|
1257
|
+
/**
|
|
1258
|
+
* @see https://redis.io/commands/geoadd
|
|
1259
|
+
*/
|
|
1260
|
+
geoadd: (...args) => new GeoAddCommand(args, this.commandOptions).exec(this.client),
|
|
1261
|
+
/**
|
|
1262
|
+
* @see https://redis.io/commands/geodist
|
|
1263
|
+
*/
|
|
1264
|
+
geodist: (...args) => new GeoDistCommand(args, this.commandOptions).exec(this.client),
|
|
1241
1265
|
/**
|
|
1242
1266
|
* @see https://redis.io/commands/json.get
|
|
1243
1267
|
*/
|
package/esm/pkg/redis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
1
|
+
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GeoAddCommand, GeoDistCommand, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, JsonArrAppendCommand, JsonArrIndexCommand, JsonArrInsertCommand, JsonArrLenCommand, JsonArrPopCommand, JsonArrTrimCommand, JsonClearCommand, JsonDelCommand, JsonForgetCommand, JsonGetCommand, JsonMGetCommand, JsonNumIncrByCommand, JsonNumMultByCommand, JsonObjKeysCommand, JsonObjLenCommand, JsonRespCommand, JsonSetCommand, JsonStrAppendCommand, JsonStrLenCommand, JsonToggleCommand, JsonTypeCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LMoveCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMIsMemberCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, XAddCommand, XRangeCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { Pipeline } from "./pipeline.js";
|
|
3
3
|
import { Script } from "./script.js";
|
|
4
4
|
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
@@ -1005,6 +1005,24 @@ export class Redis {
|
|
|
1005
1005
|
writable: true,
|
|
1006
1006
|
value: (...args) => new UnlinkCommand(args, this.opts).exec(this.client)
|
|
1007
1007
|
});
|
|
1008
|
+
/**
|
|
1009
|
+
* @see https://redis.io/commands/xadd
|
|
1010
|
+
*/
|
|
1011
|
+
Object.defineProperty(this, "xadd", {
|
|
1012
|
+
enumerable: true,
|
|
1013
|
+
configurable: true,
|
|
1014
|
+
writable: true,
|
|
1015
|
+
value: (...args) => new XAddCommand(args, this.opts).exec(this.client)
|
|
1016
|
+
});
|
|
1017
|
+
/**
|
|
1018
|
+
* @see https://redis.io/commands/xrange
|
|
1019
|
+
*/
|
|
1020
|
+
Object.defineProperty(this, "xrange", {
|
|
1021
|
+
enumerable: true,
|
|
1022
|
+
configurable: true,
|
|
1023
|
+
writable: true,
|
|
1024
|
+
value: (...args) => new XRangeCommand(args, this.opts).exec(this.client)
|
|
1025
|
+
});
|
|
1008
1026
|
/**
|
|
1009
1027
|
* @see https://redis.io/commands/zadd
|
|
1010
1028
|
*/
|
|
@@ -1181,6 +1199,15 @@ export class Redis {
|
|
|
1181
1199
|
writable: true,
|
|
1182
1200
|
value: (key, member) => new ZScoreCommand([key, member], this.opts).exec(this.client)
|
|
1183
1201
|
});
|
|
1202
|
+
/**
|
|
1203
|
+
* @see https://redis.io/commands/zunion
|
|
1204
|
+
*/
|
|
1205
|
+
Object.defineProperty(this, "zunion", {
|
|
1206
|
+
enumerable: true,
|
|
1207
|
+
configurable: true,
|
|
1208
|
+
writable: true,
|
|
1209
|
+
value: (...args) => new ZUnionCommand(args, this.opts).exec(this.client)
|
|
1210
|
+
});
|
|
1184
1211
|
/**
|
|
1185
1212
|
* @see https://redis.io/commands/zunionstore
|
|
1186
1213
|
*/
|
|
@@ -1232,6 +1259,14 @@ export class Redis {
|
|
|
1232
1259
|
* @see https://redis.io/commands/json.forget
|
|
1233
1260
|
*/
|
|
1234
1261
|
forget: (...args) => new JsonForgetCommand(args, this.opts).exec(this.client),
|
|
1262
|
+
/**
|
|
1263
|
+
* @see https://redis.io/commands/geoadd
|
|
1264
|
+
*/
|
|
1265
|
+
geoadd: (...args) => new GeoAddCommand(args, this.opts).exec(this.client),
|
|
1266
|
+
/**
|
|
1267
|
+
* @see https://redis.io/commands/geodist
|
|
1268
|
+
*/
|
|
1269
|
+
geodist: (...args) => new GeoDistCommand(args, this.opts).exec(this.client),
|
|
1235
1270
|
/**
|
|
1236
1271
|
* @see https://redis.io/commands/json.get
|
|
1237
1272
|
*/
|
package/esm/platforms/nodejs.js
CHANGED
|
@@ -35,14 +35,16 @@ export class Redis extends core.Redis {
|
|
|
35
35
|
headers: { authorization: `Bearer ${configOrRequester.token}` },
|
|
36
36
|
agent: configOrRequester.agent,
|
|
37
37
|
responseEncoding: configOrRequester.responseEncoding,
|
|
38
|
-
cache: "no-store",
|
|
38
|
+
cache: configOrRequester.cache || "no-store",
|
|
39
39
|
});
|
|
40
40
|
super(client, {
|
|
41
41
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
42
42
|
enableTelemetry: !process.env.UPSTASH_DISABLE_TELEMETRY,
|
|
43
43
|
});
|
|
44
44
|
this.addTelemetry({
|
|
45
|
-
runtime:
|
|
45
|
+
runtime: typeof EdgeRuntime === "string"
|
|
46
|
+
? "edge-light"
|
|
47
|
+
: `node@${process.version}`,
|
|
46
48
|
platform: process.env.VERCEL
|
|
47
49
|
? "vercel"
|
|
48
50
|
: process.env.AWS_REGION
|
package/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "v0.0.0-ci.
|
|
1
|
+
export const VERSION = "v0.0.0-ci.b3f07153-20231018";
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "./script/platforms/nodejs.js",
|
|
4
4
|
"types": "./types/platforms/nodejs.d.ts",
|
|
5
5
|
"name": "@upstash/redis",
|
|
6
|
-
"version": "v0.0.0-ci.
|
|
6
|
+
"version": "v0.0.0-ci.b3f07153-20231018",
|
|
7
7
|
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -27,10 +27,18 @@
|
|
|
27
27
|
},
|
|
28
28
|
"typesVersions": {
|
|
29
29
|
"*": {
|
|
30
|
-
"nodejs":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
30
|
+
"nodejs": [
|
|
31
|
+
"./types/platforms/nodejs.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"cloudflare": [
|
|
34
|
+
"./types/platforms/cloudflare.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"fastly": [
|
|
37
|
+
"./types/platforms/fastly.d.ts"
|
|
38
|
+
],
|
|
39
|
+
"with-fetch": [
|
|
40
|
+
"./types/platforms/node_with_fetch.d.ts"
|
|
41
|
+
]
|
|
34
42
|
}
|
|
35
43
|
},
|
|
36
44
|
"exports": {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoAddCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/geoadd
|
|
7
|
+
*/
|
|
8
|
+
class GeoAddCommand extends command_js_1.Command {
|
|
9
|
+
constructor([key, arg1, ...arg2], opts) {
|
|
10
|
+
const command = ["geoadd", key];
|
|
11
|
+
if ("nx" in arg1 && arg1.nx) {
|
|
12
|
+
command.push("nx");
|
|
13
|
+
}
|
|
14
|
+
else if ("xx" in arg1 && arg1.xx) {
|
|
15
|
+
command.push("xx");
|
|
16
|
+
}
|
|
17
|
+
if ("ch" in arg1 && arg1.ch) {
|
|
18
|
+
command.push("ch");
|
|
19
|
+
}
|
|
20
|
+
if ("latitude" in arg1 && arg1.latitude) {
|
|
21
|
+
command.push(arg1.longitude, arg1.latitude, arg1.member);
|
|
22
|
+
}
|
|
23
|
+
command.push(...arg2.flatMap(({ latitude, longitude, member }) => [
|
|
24
|
+
longitude,
|
|
25
|
+
latitude,
|
|
26
|
+
member,
|
|
27
|
+
]));
|
|
28
|
+
super(command, opts);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.GeoAddCommand = GeoAddCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoDistCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/geodist
|
|
7
|
+
*/
|
|
8
|
+
class GeoDistCommand extends command_js_1.Command {
|
|
9
|
+
constructor([key, member1, member2, unit = "M"], opts) {
|
|
10
|
+
const command = ["GEODIST", key];
|
|
11
|
+
command.push(member1, member2, unit);
|
|
12
|
+
super(command, opts);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.GeoDistCommand = GeoDistCommand;
|
|
@@ -11,7 +11,15 @@ function deserialize(result) {
|
|
|
11
11
|
const key = result.shift();
|
|
12
12
|
const value = result.shift();
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// handle unsafe integer
|
|
15
|
+
const valueIsNumberAndNotSafeInteger = !isNaN(Number(value)) &&
|
|
16
|
+
!Number.isSafeInteger(value);
|
|
17
|
+
if (valueIsNumberAndNotSafeInteger) {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
obj[key] = JSON.parse(value);
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
24
|
catch {
|
|
17
25
|
obj[key] = value;
|
|
@@ -31,6 +31,8 @@ __exportStar(require("./expire.js"), exports);
|
|
|
31
31
|
__exportStar(require("./expireat.js"), exports);
|
|
32
32
|
__exportStar(require("./flushall.js"), exports);
|
|
33
33
|
__exportStar(require("./flushdb.js"), exports);
|
|
34
|
+
__exportStar(require("./geo_add.js"), exports);
|
|
35
|
+
__exportStar(require("./geo_dist.js"), exports);
|
|
34
36
|
__exportStar(require("./get.js"), exports);
|
|
35
37
|
__exportStar(require("./getbit.js"), exports);
|
|
36
38
|
__exportStar(require("./getdel.js"), exports);
|
|
@@ -153,4 +155,7 @@ __exportStar(require("./zremrangebyscore.js"), exports);
|
|
|
153
155
|
__exportStar(require("./zrevrank.js"), exports);
|
|
154
156
|
__exportStar(require("./zscan.js"), exports);
|
|
155
157
|
__exportStar(require("./zscore.js"), exports);
|
|
158
|
+
__exportStar(require("./zunion.js"), exports);
|
|
156
159
|
__exportStar(require("./zunionstore.js"), exports);
|
|
160
|
+
__exportStar(require("./xadd.js"), exports);
|
|
161
|
+
__exportStar(require("./xrange.js"), exports);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XAddCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/xadd
|
|
7
|
+
*/
|
|
8
|
+
class XAddCommand extends command_js_1.Command {
|
|
9
|
+
constructor([key, id, entries, opts], commandOptions) {
|
|
10
|
+
const command = ["XADD", key];
|
|
11
|
+
if (opts) {
|
|
12
|
+
if (opts.nomkStream) {
|
|
13
|
+
command.push("NOMKSTREAM");
|
|
14
|
+
}
|
|
15
|
+
if (opts.trim) {
|
|
16
|
+
command.push(opts.trim.type, opts.trim.comparison, opts.trim.threshold);
|
|
17
|
+
if (typeof opts.trim.limit !== "undefined") {
|
|
18
|
+
command.push("LIMIT", opts.trim.limit);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
command.push(id);
|
|
23
|
+
// entries
|
|
24
|
+
Object.entries(entries).forEach(([k, v]) => {
|
|
25
|
+
command.push(k, v);
|
|
26
|
+
});
|
|
27
|
+
super(command, commandOptions);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.XAddCommand = XAddCommand;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XRangeCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
function deserialize(result) {
|
|
6
|
+
const obj = {};
|
|
7
|
+
for (const e of result) {
|
|
8
|
+
while (e.length >= 2) {
|
|
9
|
+
const streamId = e.shift();
|
|
10
|
+
const entries = e.shift();
|
|
11
|
+
if (!(streamId in obj)) {
|
|
12
|
+
obj[streamId] = {};
|
|
13
|
+
}
|
|
14
|
+
while (entries.length >= 2) {
|
|
15
|
+
const field = entries.shift();
|
|
16
|
+
const value = entries.shift();
|
|
17
|
+
try {
|
|
18
|
+
obj[streamId][field] = JSON.parse(value);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
obj[streamId][field] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
class XRangeCommand extends command_js_1.Command {
|
|
29
|
+
constructor([key, start, end, count], opts) {
|
|
30
|
+
const command = ["XRANGE", key, start, end];
|
|
31
|
+
if (typeof count === "number") {
|
|
32
|
+
command.push("COUNT", count);
|
|
33
|
+
}
|
|
34
|
+
super(command, {
|
|
35
|
+
deserialize: (result) => deserialize(result),
|
|
36
|
+
...opts,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.XRangeCommand = XRangeCommand;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZUnionCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/zunion
|
|
7
|
+
*/
|
|
8
|
+
class ZUnionCommand extends command_js_1.Command {
|
|
9
|
+
constructor([numKeys, keyOrKeys, opts], cmdOpts) {
|
|
10
|
+
const command = ["zunion", numKeys];
|
|
11
|
+
if (Array.isArray(keyOrKeys)) {
|
|
12
|
+
command.push(...keyOrKeys);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
command.push(keyOrKeys);
|
|
16
|
+
}
|
|
17
|
+
if (opts) {
|
|
18
|
+
if ("weights" in opts && opts.weights) {
|
|
19
|
+
command.push("weights", ...opts.weights);
|
|
20
|
+
}
|
|
21
|
+
else if ("weight" in opts && typeof opts.weight === "number") {
|
|
22
|
+
command.push("weights", opts.weight);
|
|
23
|
+
}
|
|
24
|
+
if ("aggregate" in opts) {
|
|
25
|
+
command.push("aggregate", opts.aggregate);
|
|
26
|
+
}
|
|
27
|
+
if (opts?.withScores) {
|
|
28
|
+
command.push("withscores");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
super(command, cmdOpts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ZUnionCommand = ZUnionCommand;
|