@upstash/redis 1.17.0 → 1.18.1-rc.0

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.
@@ -1,8 +1,4 @@
1
1
  import { Command } from "./command.js";
2
- /**
3
- * @param result De
4
- * @returns
5
- */
6
2
  function deserialize(result) {
7
3
  if (result.length === 0) {
8
4
  return null;
@@ -0,0 +1,39 @@
1
+ import { Command } from "./command.js";
2
+ function deserialize(result) {
3
+ if (result.length === 0) {
4
+ return null;
5
+ }
6
+ const obj = {};
7
+ while (result.length >= 2) {
8
+ const key = result.shift();
9
+ const value = result.shift();
10
+ try {
11
+ obj[key] = JSON.parse(value);
12
+ }
13
+ catch {
14
+ obj[key] = value;
15
+ }
16
+ }
17
+ return obj;
18
+ }
19
+ /**
20
+ * @see https://redis.io/commands/hrandfield
21
+ */
22
+ export class HRandFieldCommand extends Command {
23
+ constructor(cmd, opts) {
24
+ const command = ["hrandfield", cmd[0]];
25
+ if (typeof cmd[1] === "number") {
26
+ command.push(cmd[1]);
27
+ }
28
+ if (cmd[2]) {
29
+ command.push("WITHVALUES");
30
+ }
31
+ super(command, {
32
+ // @ts-ignore TODO:
33
+ deserialize: cmd[2]
34
+ ? (result) => deserialize(result)
35
+ : opts?.deserialize,
36
+ ...opts,
37
+ });
38
+ }
39
+ }
@@ -17,9 +17,9 @@ export * from "./flushall.js";
17
17
  export * from "./flushdb.js";
18
18
  export * from "./get.js";
19
19
  export * from "./getbit.js";
20
+ export * from "./getdel.js";
20
21
  export * from "./getrange.js";
21
22
  export * from "./getset.js";
22
- export * from "./getdel.js";
23
23
  export * from "./hdel.js";
24
24
  export * from "./hexists.js";
25
25
  export * from "./hget.js";
@@ -30,6 +30,7 @@ export * from "./hkeys.js";
30
30
  export * from "./hlen.js";
31
31
  export * from "./hmget.js";
32
32
  export * from "./hmset.js";
33
+ export * from "./hrandfield.js";
33
34
  export * from "./hscan.js";
34
35
  export * from "./hset.js";
35
36
  export * from "./hsetnx.js";
@@ -1,6 +1,7 @@
1
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, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, 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, 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";
2
2
  import { UpstashError } from "./error.js";
3
3
  import { ZMScoreCommand } from "./commands/zmscore.js";
4
+ import { HRandFieldCommand } from "./commands/hrandfield.js";
4
5
  /**
5
6
  * Upstash REST API supports command pipelining to send multiple commands in
6
7
  * batch, instead of sending each command one by one and waiting for a response.
@@ -375,6 +376,15 @@ export class Pipeline {
375
376
  writable: true,
376
377
  value: (key, kv) => this.chain(new HMSetCommand([key, kv], this.commandOptions))
377
378
  });
379
+ /**
380
+ * @see https://redis.io/commands/hrandfield
381
+ */
382
+ Object.defineProperty(this, "hrandfield", {
383
+ enumerable: true,
384
+ configurable: true,
385
+ writable: true,
386
+ value: (key, count, withValues) => this.chain(new HRandFieldCommand([key, count, withValues], this.commandOptions))
387
+ });
378
388
  /**
379
389
  * @see https://redis.io/commands/hscan
380
390
  */
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, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, 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, 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, GetBitCommand, GetCommand, GetDelCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HRandFieldCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, 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, 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";
2
2
  import { Pipeline } from "./pipeline.js";
3
3
  import { Script } from "./script.js";
4
4
  import { ZMScoreCommand } from "./commands/zmscore.js";
@@ -355,6 +355,16 @@ export class Redis {
355
355
  writable: true,
356
356
  value: (key, kv) => new HMSetCommand([key, kv], this.opts).exec(this.client)
357
357
  });
358
+ /**
359
+ * @see https://redis.io/commands/hrandfield
360
+ */
361
+ Object.defineProperty(this, "hrandfield", {
362
+ enumerable: true,
363
+ configurable: true,
364
+ writable: true,
365
+ value: (key, count, withValues) => new HRandFieldCommand([key, count, withValues], this.opts)
366
+ .exec(this.client)
367
+ });
358
368
  /**
359
369
  * @see https://redis.io/commands/hscan
360
370
  */
package/esm/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "v1.17.0";
1
+ export const VERSION = "v1.18.1-rc.0";
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": "v1.17.0",
6
+ "version": "v1.18.1-rc.0",
7
7
  "description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -2,10 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HGetAllCommand = void 0;
4
4
  const command_js_1 = require("./command.js");
5
- /**
6
- * @param result De
7
- * @returns
8
- */
9
5
  function deserialize(result) {
10
6
  if (result.length === 0) {
11
7
  return null;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HRandFieldCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ function deserialize(result) {
6
+ if (result.length === 0) {
7
+ return null;
8
+ }
9
+ const obj = {};
10
+ while (result.length >= 2) {
11
+ const key = result.shift();
12
+ const value = result.shift();
13
+ try {
14
+ obj[key] = JSON.parse(value);
15
+ }
16
+ catch {
17
+ obj[key] = value;
18
+ }
19
+ }
20
+ return obj;
21
+ }
22
+ /**
23
+ * @see https://redis.io/commands/hrandfield
24
+ */
25
+ class HRandFieldCommand extends command_js_1.Command {
26
+ constructor(cmd, opts) {
27
+ const command = ["hrandfield", cmd[0]];
28
+ if (typeof cmd[1] === "number") {
29
+ command.push(cmd[1]);
30
+ }
31
+ if (cmd[2]) {
32
+ command.push("WITHVALUES");
33
+ }
34
+ super(command, {
35
+ // @ts-ignore TODO:
36
+ deserialize: cmd[2]
37
+ ? (result) => deserialize(result)
38
+ : opts?.deserialize,
39
+ ...opts,
40
+ });
41
+ }
42
+ }
43
+ exports.HRandFieldCommand = HRandFieldCommand;
@@ -33,9 +33,9 @@ __exportStar(require("./flushall.js"), exports);
33
33
  __exportStar(require("./flushdb.js"), exports);
34
34
  __exportStar(require("./get.js"), exports);
35
35
  __exportStar(require("./getbit.js"), exports);
36
+ __exportStar(require("./getdel.js"), exports);
36
37
  __exportStar(require("./getrange.js"), exports);
37
38
  __exportStar(require("./getset.js"), exports);
38
- __exportStar(require("./getdel.js"), exports);
39
39
  __exportStar(require("./hdel.js"), exports);
40
40
  __exportStar(require("./hexists.js"), exports);
41
41
  __exportStar(require("./hget.js"), exports);
@@ -46,6 +46,7 @@ __exportStar(require("./hkeys.js"), exports);
46
46
  __exportStar(require("./hlen.js"), exports);
47
47
  __exportStar(require("./hmget.js"), exports);
48
48
  __exportStar(require("./hmset.js"), exports);
49
+ __exportStar(require("./hrandfield.js"), exports);
49
50
  __exportStar(require("./hscan.js"), exports);
50
51
  __exportStar(require("./hset.js"), exports);
51
52
  __exportStar(require("./hsetnx.js"), exports);
@@ -4,6 +4,7 @@ exports.Pipeline = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const error_js_1 = require("./error.js");
6
6
  const zmscore_js_1 = require("./commands/zmscore.js");
7
+ const hrandfield_js_1 = require("./commands/hrandfield.js");
7
8
  /**
8
9
  * Upstash REST API supports command pipelining to send multiple commands in
9
10
  * batch, instead of sending each command one by one and waiting for a response.
@@ -378,6 +379,15 @@ class Pipeline {
378
379
  writable: true,
379
380
  value: (key, kv) => this.chain(new mod_js_1.HMSetCommand([key, kv], this.commandOptions))
380
381
  });
382
+ /**
383
+ * @see https://redis.io/commands/hrandfield
384
+ */
385
+ Object.defineProperty(this, "hrandfield", {
386
+ enumerable: true,
387
+ configurable: true,
388
+ writable: true,
389
+ value: (key, count, withValues) => this.chain(new hrandfield_js_1.HRandFieldCommand([key, count, withValues], this.commandOptions))
390
+ });
381
391
  /**
382
392
  * @see https://redis.io/commands/hscan
383
393
  */
@@ -358,6 +358,16 @@ class Redis {
358
358
  writable: true,
359
359
  value: (key, kv) => new mod_js_1.HMSetCommand([key, kv], this.opts).exec(this.client)
360
360
  });
361
+ /**
362
+ * @see https://redis.io/commands/hrandfield
363
+ */
364
+ Object.defineProperty(this, "hrandfield", {
365
+ enumerable: true,
366
+ configurable: true,
367
+ writable: true,
368
+ value: (key, count, withValues) => new mod_js_1.HRandFieldCommand([key, count, withValues], this.opts)
369
+ .exec(this.client)
370
+ });
361
371
  /**
362
372
  * @see https://redis.io/commands/hscan
363
373
  */
package/script/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "v1.17.0";
4
+ exports.VERSION = "v1.18.1-rc.0";
@@ -0,0 +1,9 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/hrandfield
4
+ */
5
+ export declare class HRandFieldCommand<TData extends string | string[] | Record<string, unknown>> extends Command<string | string[], TData> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<string, string>);
7
+ constructor(cmd: [key: string, count: number], opts?: CommandOptions<string[], string[]>);
8
+ constructor(cmd: [key: string, count: number, withValues: boolean], opts?: CommandOptions<string[], Partial<TData>>);
9
+ }
@@ -17,9 +17,9 @@ export * from "./flushall.js";
17
17
  export * from "./flushdb.js";
18
18
  export * from "./get.js";
19
19
  export * from "./getbit.js";
20
+ export * from "./getdel.js";
20
21
  export * from "./getrange.js";
21
22
  export * from "./getset.js";
22
- export * from "./getdel.js";
23
23
  export * from "./hdel.js";
24
24
  export * from "./hexists.js";
25
25
  export * from "./hget.js";
@@ -30,6 +30,7 @@ export * from "./hkeys.js";
30
30
  export * from "./hlen.js";
31
31
  export * from "./hmget.js";
32
32
  export * from "./hmset.js";
33
+ export * from "./hrandfield.js";
33
34
  export * from "./hscan.js";
34
35
  export * from "./hset.js";
35
36
  export * from "./hsetnx.js";
@@ -197,6 +197,10 @@ export declare class Pipeline {
197
197
  hmset: <TData>(key: string, kv: {
198
198
  [field: string]: TData;
199
199
  }) => this;
200
+ /**
201
+ * @see https://redis.io/commands/hrandfield
202
+ */
203
+ hrandfield: <TData extends string | string[] | Record<string, unknown>>(key: string, count?: number, withValues?: boolean) => this;
200
204
  /**
201
205
  * @see https://redis.io/commands/hscan
202
206
  */
@@ -181,6 +181,14 @@ export declare class Redis {
181
181
  hmset: <TData>(key: string, kv: {
182
182
  [field: string]: TData;
183
183
  }) => Promise<"OK">;
184
+ /**
185
+ * @see https://redis.io/commands/hrandfield
186
+ */
187
+ hrandfield: {
188
+ (key: string): Promise<string>;
189
+ (key: string, count: number): Promise<string[]>;
190
+ <TData extends Record<string, unknown>>(key: string, count: number, withValues: boolean): Promise<Partial<TData>>;
191
+ };
184
192
  /**
185
193
  * @see https://redis.io/commands/hscan
186
194
  */
@@ -1 +1 @@
1
- export declare const VERSION = "v1.17.0";
1
+ export declare const VERSION = "v1.18.1-rc.0";