@upstash/redis 0.0.0-ci.e9b0c868305a820aaed7d68c8407b277da5a093e-20241008121230 → 0.0.0-ci.ea9f0853d6a86e6b7809a21bff609de1b6e9291d-20250414063537

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.
@@ -36,7 +36,23 @@ type UpstashRequest = {
36
36
  * Request body will be serialized to json
37
37
  */
38
38
  body?: unknown;
39
+ /**
40
+ * Additional headers for the request
41
+ */
42
+ headers?: Record<string, string>;
39
43
  upstashSyncToken?: string;
44
+ /**
45
+ * Callback for handling streaming messages
46
+ */
47
+ onMessage?: (data: string) => void;
48
+ /**
49
+ * Whether this request expects a streaming response
50
+ */
51
+ isStreaming?: boolean;
52
+ /**
53
+ * Abort signal for the request
54
+ */
55
+ signal?: AbortSignal;
40
56
  };
41
57
  type UpstashResponse<TResult> = {
42
58
  result?: TResult;
@@ -119,6 +135,31 @@ type CommandOptions<TResult, TData> = {
119
135
  */
120
136
  automaticDeserialization?: boolean;
121
137
  latencyLogging?: boolean;
138
+ /**
139
+ * Additional headers to be sent with the request
140
+ */
141
+ headers?: Record<string, string>;
142
+ /**
143
+ * Path to append to the URL
144
+ */
145
+ path?: string[];
146
+ /**
147
+ * Options for streaming requests, mainly used for subscribe, monitor commands
148
+ **/
149
+ streamOptions?: {
150
+ /**
151
+ * Callback to be called when a message is received
152
+ */
153
+ onMessage?: (data: string) => void;
154
+ /**
155
+ * Whether the request is streaming
156
+ */
157
+ isStreaming?: boolean;
158
+ /**
159
+ * Signal to abort the request
160
+ */
161
+ signal?: AbortSignal;
162
+ };
122
163
  };
123
164
  /**
124
165
  * Command offers default (de)serialization and the exec method to all commands.
@@ -130,6 +171,11 @@ declare class Command<TResult, TData> {
130
171
  readonly command: (string | number | boolean)[];
131
172
  readonly serialize: Serialize;
132
173
  readonly deserialize: Deserialize<TResult, TData>;
174
+ protected readonly headers?: Record<string, string>;
175
+ protected readonly path?: string[];
176
+ protected readonly onMessage?: (data: string) => void;
177
+ protected readonly isStreaming: boolean;
178
+ protected readonly signal?: AbortSignal;
133
179
  /**
134
180
  * Create a new command instance.
135
181
  *
@@ -262,6 +308,11 @@ declare class GeoAddCommand<TMemberType = string> extends Command<number | null,
262
308
  ], opts?: CommandOptions<number | null, number | null>);
263
309
  }
264
310
 
311
+ type ExpireOption = "NX" | "nx" | "XX" | "xx" | "GT" | "gt" | "LT" | "lt";
312
+ declare class ExpireCommand extends Command<"0" | "1", 0 | 1> {
313
+ constructor(cmd: [key: string, seconds: number, option?: ExpireOption], opts?: CommandOptions<"0" | "1", 0 | 1>);
314
+ }
315
+
265
316
  /**
266
317
  * @see https://redis.io/commands/append
267
318
  */
@@ -358,6 +409,13 @@ declare class EchoCommand extends Command<string, string> {
358
409
  constructor(cmd: [message: string], opts?: CommandOptions<string, string>);
359
410
  }
360
411
 
412
+ /**
413
+ * @see https://redis.io/commands/eval_ro
414
+ */
415
+ declare class EvalROCommand<TArgs extends unknown[], TData> extends Command<unknown, TData> {
416
+ constructor([script, keys, args]: [script: string, keys: string[], args: TArgs], opts?: CommandOptions<unknown, TData>);
417
+ }
418
+
361
419
  /**
362
420
  * @see https://redis.io/commands/eval
363
421
  */
@@ -365,6 +423,13 @@ declare class EvalCommand<TArgs extends unknown[], TData> extends Command<unknow
365
423
  constructor([script, keys, args]: [script: string, keys: string[], args: TArgs], opts?: CommandOptions<unknown, TData>);
366
424
  }
367
425
 
426
+ /**
427
+ * @see https://redis.io/commands/evalsha_ro
428
+ */
429
+ declare class EvalshaROCommand<TArgs extends unknown[], TData> extends Command<unknown, TData> {
430
+ constructor([sha, keys, args]: [sha: string, keys: string[], args?: TArgs], opts?: CommandOptions<unknown, TData>);
431
+ }
432
+
368
433
  /**
369
434
  * @see https://redis.io/commands/evalsha
370
435
  */
@@ -379,16 +444,11 @@ declare class ExistsCommand extends Command<number, number> {
379
444
  constructor(cmd: [...keys: string[]], opts?: CommandOptions<number, number>);
380
445
  }
381
446
 
382
- type ExpireOptions = "NX" | "nx" | "XX" | "xx" | "GT" | "gt" | "LT" | "lt";
383
- declare class ExpireCommand extends Command<"0" | "1", 0 | 1> {
384
- constructor(cmd: [key: string, seconds: number, option?: ExpireOptions], opts?: CommandOptions<"0" | "1", 0 | 1>);
385
- }
386
-
387
447
  /**
388
448
  * @see https://redis.io/commands/expireat
389
449
  */
390
450
  declare class ExpireAtCommand extends Command<"0" | "1", 0 | 1> {
391
- constructor(cmd: [key: string, unix: number], opts?: CommandOptions<"0" | "1", 0 | 1>);
451
+ constructor(cmd: [key: string, unix: number, option?: ExpireOption], opts?: CommandOptions<"0" | "1", 0 | 1>);
392
452
  }
393
453
 
394
454
  /**
@@ -563,6 +623,50 @@ declare class GetDelCommand<TData = string> extends Command<unknown | null, TDat
563
623
  constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
564
624
  }
565
625
 
626
+ type GetExCommandOptions = {
627
+ ex: number;
628
+ px?: never;
629
+ exat?: never;
630
+ pxat?: never;
631
+ persist?: never;
632
+ } | {
633
+ ex?: never;
634
+ px: number;
635
+ exat?: never;
636
+ pxat?: never;
637
+ persist?: never;
638
+ } | {
639
+ ex?: never;
640
+ px?: never;
641
+ exat: number;
642
+ pxat?: never;
643
+ persist?: never;
644
+ } | {
645
+ ex?: never;
646
+ px?: never;
647
+ exat?: never;
648
+ pxat: number;
649
+ persist?: never;
650
+ } | {
651
+ ex?: never;
652
+ px?: never;
653
+ exat?: never;
654
+ pxat?: never;
655
+ persist: true;
656
+ } | {
657
+ ex?: never;
658
+ px?: never;
659
+ exat?: never;
660
+ pxat?: never;
661
+ persist?: never;
662
+ };
663
+ /**
664
+ * @see https://redis.io/commands/getex
665
+ */
666
+ declare class GetExCommand<TData = string> extends Command<unknown | null, TData | null> {
667
+ constructor([key, opts]: [key: string, opts?: GetExCommandOptions], cmdOpts?: CommandOptions<unknown | null, TData | null>);
668
+ }
669
+
566
670
  /**
567
671
  * @see https://redis.io/commands/getrange
568
672
  */
@@ -591,6 +695,58 @@ declare class HExistsCommand extends Command<number, number> {
591
695
  constructor(cmd: [key: string, field: string], opts?: CommandOptions<number, number>);
592
696
  }
593
697
 
698
+ declare class HExpireCommand extends Command<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]> {
699
+ constructor(cmd: [
700
+ key: string,
701
+ fields: (string | number) | (string | number)[],
702
+ seconds: number,
703
+ option?: ExpireOption
704
+ ], opts?: CommandOptions<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]>);
705
+ }
706
+
707
+ declare class HExpireAtCommand extends Command<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]> {
708
+ constructor(cmd: [
709
+ key: string,
710
+ fields: (string | number) | (string | number)[],
711
+ timestamp: number,
712
+ option?: ExpireOption
713
+ ], opts?: CommandOptions<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]>);
714
+ }
715
+
716
+ declare class HExpireTimeCommand extends Command<number[], number[]> {
717
+ constructor(cmd: [key: string, fields: (string | number) | (string | number)[]], opts?: CommandOptions<number[], number[]>);
718
+ }
719
+
720
+ declare class HPersistCommand extends Command<(-2 | -1 | 1)[], (-2 | -1 | 1)[]> {
721
+ constructor(cmd: [key: string, fields: (string | number) | (string | number)[]], opts?: CommandOptions<(-2 | -1 | 1)[], (-2 | -1 | 1)[]>);
722
+ }
723
+
724
+ declare class HPExpireCommand extends Command<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]> {
725
+ constructor(cmd: [
726
+ key: string,
727
+ fields: (string | number) | (string | number)[],
728
+ milliseconds: number,
729
+ option?: ExpireOption
730
+ ], opts?: CommandOptions<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]>);
731
+ }
732
+
733
+ declare class HPExpireAtCommand extends Command<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]> {
734
+ constructor(cmd: [
735
+ key: string,
736
+ fields: (string | number) | (string | number)[],
737
+ timestamp: number,
738
+ option?: ExpireOption
739
+ ], opts?: CommandOptions<(-2 | 0 | 1 | 2)[], (-2 | 0 | 1 | 2)[]>);
740
+ }
741
+
742
+ declare class HPExpireTimeCommand extends Command<number[], number[]> {
743
+ constructor(cmd: [key: string, fields: (string | number) | (string | number)[]], opts?: CommandOptions<number[], number[]>);
744
+ }
745
+
746
+ declare class HPTtlCommand extends Command<number[], number[]> {
747
+ constructor(cmd: [key: string, fields: (string | number) | (string | number)[]], opts?: CommandOptions<number[], number[]>);
748
+ }
749
+
594
750
  /**
595
751
  * @see https://redis.io/commands/hget
596
752
  */
@@ -698,6 +854,10 @@ declare class HStrLenCommand extends Command<number, number> {
698
854
  constructor(cmd: [key: string, field: string], opts?: CommandOptions<number, number>);
699
855
  }
700
856
 
857
+ declare class HTtlCommand extends Command<number[], number[]> {
858
+ constructor(cmd: [key: string, fields: (string | number) | (string | number)[]], opts?: CommandOptions<number[], number[]>);
859
+ }
860
+
701
861
  /**
702
862
  * @see https://redis.io/commands/hvals
703
863
  */
@@ -804,6 +964,13 @@ declare class JsonGetCommand<TData extends (unknown | Record<string, unknown>) |
804
964
  ] | [key: string, ...path: string[]], opts?: CommandOptions<TData | null, TData | null>);
805
965
  }
806
966
 
967
+ /**
968
+ * @see https://redis.io/commands/json.merge
969
+ */
970
+ declare class JsonMergeCommand<TData extends string | number | Record<string, unknown> | Array<unknown>> extends Command<"OK" | null, "OK" | null> {
971
+ constructor(cmd: [key: string, path: string, value: TData], opts?: CommandOptions<"OK" | null, "OK" | null>);
972
+ }
973
+
807
974
  /**
808
975
  * @see https://redis.io/commands/json.mget
809
976
  */
@@ -1006,14 +1173,14 @@ declare class PersistCommand extends Command<"0" | "1", 0 | 1> {
1006
1173
  * @see https://redis.io/commands/pexpire
1007
1174
  */
1008
1175
  declare class PExpireCommand extends Command<"0" | "1", 0 | 1> {
1009
- constructor(cmd: [key: string, milliseconds: number], opts?: CommandOptions<"0" | "1", 0 | 1>);
1176
+ constructor(cmd: [key: string, milliseconds: number, option?: ExpireOption], opts?: CommandOptions<"0" | "1", 0 | 1>);
1010
1177
  }
1011
1178
 
1012
1179
  /**
1013
1180
  * @see https://redis.io/commands/pexpireat
1014
1181
  */
1015
1182
  declare class PExpireAtCommand extends Command<"0" | "1", 0 | 1> {
1016
- constructor(cmd: [key: string, unix: number], opts?: CommandOptions<"0" | "1", 0 | 1>);
1183
+ constructor(cmd: [key: string, unix: number, option?: ExpireOption], opts?: CommandOptions<"0" | "1", 0 | 1>);
1017
1184
  }
1018
1185
 
1019
1186
  /**
@@ -1599,9 +1766,78 @@ declare class ZScoreCommand<TData> extends Command<string | null, number | null>
1599
1766
  constructor(cmd: [key: string, member: TData], opts?: CommandOptions<string | null, number | null>);
1600
1767
  }
1601
1768
 
1769
+ type BaseMessageData<TMessage> = {
1770
+ channel: string;
1771
+ message: TMessage;
1772
+ };
1773
+ type PatternMessageData<TMessage> = BaseMessageData<TMessage> & {
1774
+ pattern: string;
1775
+ };
1776
+ type SubscriptionCountEvent = number;
1777
+ type MessageEventMap<TMessage> = {
1778
+ message: BaseMessageData<TMessage>;
1779
+ subscribe: SubscriptionCountEvent;
1780
+ unsubscribe: SubscriptionCountEvent;
1781
+ pmessage: PatternMessageData<TMessage>;
1782
+ psubscribe: SubscriptionCountEvent;
1783
+ punsubscribe: SubscriptionCountEvent;
1784
+ error: Error;
1785
+ [key: `message:${string}`]: BaseMessageData<TMessage>;
1786
+ [key: `pmessage:${string}`]: PatternMessageData<TMessage>;
1787
+ };
1788
+ type EventType = keyof MessageEventMap<any>;
1789
+ type Listener<TMessage, T extends EventType> = (event: MessageEventMap<TMessage>[T]) => void;
1790
+ declare class Subscriber<TMessage = any> extends EventTarget {
1791
+ private subscriptions;
1792
+ private client;
1793
+ private listeners;
1794
+ constructor(client: Requester, channels: string[], isPattern?: boolean);
1795
+ private subscribeToChannel;
1796
+ private subscribeToPattern;
1797
+ private handleMessage;
1798
+ private dispatchToListeners;
1799
+ on<T extends keyof MessageEventMap<TMessage>>(type: T, listener: Listener<TMessage, T>): void;
1800
+ removeAllListeners(): void;
1801
+ unsubscribe(channels?: string[]): Promise<void>;
1802
+ getSubscribedChannels(): string[];
1803
+ }
1804
+
1602
1805
  type InferResponseData<T extends unknown[]> = {
1603
1806
  [K in keyof T]: T[K] extends Command<any, infer TData> ? TData : unknown;
1604
1807
  };
1808
+ interface ExecMethod<TCommands extends Command<any, any>[]> {
1809
+ /**
1810
+ * Send the pipeline request to upstash.
1811
+ *
1812
+ * Returns an array with the results of all pipelined commands.
1813
+ *
1814
+ * If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:
1815
+ * ```ts
1816
+ * const p = redis.pipeline()
1817
+ * p.get("key")
1818
+ * const result = p.exec<[{ greeting: string }]>()
1819
+ * ```
1820
+ *
1821
+ * If one of the commands get an error, the whole pipeline fails. Alternatively, you can set the keepErrors option to true in order to get the errors individually.
1822
+ *
1823
+ * If keepErrors is set to true, a list of objects is returned where each object corresponds to a command and is of type: `{ result: unknown, error?: string }`.
1824
+ *
1825
+ * ```ts
1826
+ * const p = redis.pipeline()
1827
+ * p.get("key")
1828
+ *
1829
+ * const result = await p.exec({ keepErrors: true });
1830
+ * const getResult = result[0].result
1831
+ * const getError = result[0].error
1832
+ * ```
1833
+ */
1834
+ <TCommandResults extends unknown[] = [] extends TCommands ? unknown[] : InferResponseData<TCommands>>(): Promise<TCommandResults>;
1835
+ <TCommandResults extends unknown[] = [] extends TCommands ? unknown[] : InferResponseData<TCommands>>(options: {
1836
+ keepErrors: true;
1837
+ }): Promise<{
1838
+ [K in keyof TCommandResults]: UpstashResponse<TCommandResults[K]>;
1839
+ }>;
1840
+ }
1605
1841
  /**
1606
1842
  * Upstash REST API supports command pipelining to send multiple commands in
1607
1843
  * batch, instead of sending each command one by one and waiting for a response.
@@ -1650,19 +1886,7 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
1650
1886
  commandOptions?: CommandOptions<any, any>;
1651
1887
  multiExec?: boolean;
1652
1888
  });
1653
- /**
1654
- * Send the pipeline request to upstash.
1655
- *
1656
- * Returns an array with the results of all pipelined commands.
1657
- *
1658
- * If all commands are statically chained from start to finish, types are inferred. You can still define a return type manually if necessary though:
1659
- * ```ts
1660
- * const p = redis.pipeline()
1661
- * p.get("key")
1662
- * const result = p.exec<[{ greeting: string }]>()
1663
- * ```
1664
- */
1665
- exec: <TCommandResults extends unknown[] = [] extends TCommands ? unknown[] : InferResponseData<TCommands>>() => Promise<TCommandResults>;
1889
+ exec: ExecMethod<TCommands>;
1666
1890
  /**
1667
1891
  * Returns the length of pipeline before the execution
1668
1892
  */
@@ -1738,10 +1962,18 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
1738
1962
  * @see https://redis.io/commands/echo
1739
1963
  */
1740
1964
  echo: (message: string) => Pipeline<[...TCommands, Command<any, string>]>;
1965
+ /**
1966
+ * @see https://redis.io/commands/eval_ro
1967
+ */
1968
+ evalRo: <TArgs extends unknown[], TData = unknown>(script: string, keys: string[], args: TArgs) => Pipeline<[...TCommands, Command<any, TData>]>;
1741
1969
  /**
1742
1970
  * @see https://redis.io/commands/eval
1743
1971
  */
1744
1972
  eval: <TArgs extends unknown[], TData = unknown>(script: string, keys: string[], args: TArgs) => Pipeline<[...TCommands, Command<any, TData>]>;
1973
+ /**
1974
+ * @see https://redis.io/commands/evalsha_ro
1975
+ */
1976
+ evalshaRo: <TArgs extends unknown[], TData = unknown>(sha1: string, keys: string[], args: TArgs) => Pipeline<[...TCommands, Command<any, TData>]>;
1745
1977
  /**
1746
1978
  * @see https://redis.io/commands/evalsha
1747
1979
  */
@@ -1753,11 +1985,11 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
1753
1985
  /**
1754
1986
  * @see https://redis.io/commands/expire
1755
1987
  */
1756
- expire: (key: string, seconds: number, option?: ("NX" | "nx" | "XX" | "xx" | "GT" | "gt" | "LT" | "lt") | undefined) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
1988
+ expire: (key: string, seconds: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
1757
1989
  /**
1758
1990
  * @see https://redis.io/commands/expireat
1759
1991
  */
1760
- expireat: (key: string, unix: number) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
1992
+ expireat: (key: string, unix: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
1761
1993
  /**
1762
1994
  * @see https://redis.io/commands/flushall
1763
1995
  */
@@ -1870,6 +2102,46 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
1870
2102
  * @see https://redis.io/commands/getdel
1871
2103
  */
1872
2104
  getdel: <TData>(key: string) => Pipeline<[...TCommands, Command<any, TData | null>]>;
2105
+ /**
2106
+ * @see https://redis.io/commands/getex
2107
+ */
2108
+ getex: <TData>(key: string, opts?: ({
2109
+ ex: number;
2110
+ px?: never;
2111
+ exat?: never;
2112
+ pxat?: never;
2113
+ persist?: never;
2114
+ } | {
2115
+ ex?: never;
2116
+ px: number;
2117
+ exat?: never;
2118
+ pxat?: never;
2119
+ persist?: never;
2120
+ } | {
2121
+ ex?: never;
2122
+ px?: never;
2123
+ exat: number;
2124
+ pxat?: never;
2125
+ persist?: never;
2126
+ } | {
2127
+ ex?: never;
2128
+ px?: never;
2129
+ exat?: never;
2130
+ pxat: number;
2131
+ persist?: never;
2132
+ } | {
2133
+ ex?: never;
2134
+ px?: never;
2135
+ exat?: never;
2136
+ pxat?: never;
2137
+ persist: true;
2138
+ } | {
2139
+ ex?: never;
2140
+ px?: never;
2141
+ exat?: never;
2142
+ pxat?: never;
2143
+ persist?: never;
2144
+ }) | undefined) => Pipeline<[...TCommands, Command<any, TData | null>]>;
1873
2145
  /**
1874
2146
  * @see https://redis.io/commands/getrange
1875
2147
  */
@@ -1886,6 +2158,42 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
1886
2158
  * @see https://redis.io/commands/hexists
1887
2159
  */
1888
2160
  hexists: (key: string, field: string) => Pipeline<[...TCommands, Command<any, number>]>;
2161
+ /**
2162
+ * @see https://redis.io/commands/hexpire
2163
+ */
2164
+ hexpire: (key: string, fields: string | number | (string | number)[], seconds: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, (0 | 1 | 2 | -2)[]>]>;
2165
+ /**
2166
+ * @see https://redis.io/commands/hexpireat
2167
+ */
2168
+ hexpireat: (key: string, fields: string | number | (string | number)[], timestamp: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, (0 | 1 | 2 | -2)[]>]>;
2169
+ /**
2170
+ * @see https://redis.io/commands/hexpiretime
2171
+ */
2172
+ hexpiretime: (key: string, fields: string | number | (string | number)[]) => Pipeline<[...TCommands, Command<any, number[]>]>;
2173
+ /**
2174
+ * @see https://redis.io/commands/httl
2175
+ */
2176
+ httl: (key: string, fields: string | number | (string | number)[]) => Pipeline<[...TCommands, Command<any, number[]>]>;
2177
+ /**
2178
+ * @see https://redis.io/commands/hpexpire
2179
+ */
2180
+ hpexpire: (key: string, fields: string | number | (string | number)[], milliseconds: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, (0 | 1 | 2 | -2)[]>]>;
2181
+ /**
2182
+ * @see https://redis.io/commands/hpexpireat
2183
+ */
2184
+ hpexpireat: (key: string, fields: string | number | (string | number)[], timestamp: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, (0 | 1 | 2 | -2)[]>]>;
2185
+ /**
2186
+ * @see https://redis.io/commands/hpexpiretime
2187
+ */
2188
+ hpexpiretime: (key: string, fields: string | number | (string | number)[]) => Pipeline<[...TCommands, Command<any, number[]>]>;
2189
+ /**
2190
+ * @see https://redis.io/commands/hpttl
2191
+ */
2192
+ hpttl: (key: string, fields: string | number | (string | number)[]) => Pipeline<[...TCommands, Command<any, number[]>]>;
2193
+ /**
2194
+ * @see https://redis.io/commands/hpersist
2195
+ */
2196
+ hpersist: (key: string, fields: string | number | (string | number)[]) => Pipeline<[...TCommands, Command<any, (1 | -2 | -1)[]>]>;
1889
2197
  /**
1890
2198
  * @see https://redis.io/commands/hget
1891
2199
  */
@@ -2033,11 +2341,11 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
2033
2341
  /**
2034
2342
  * @see https://redis.io/commands/pexpire
2035
2343
  */
2036
- pexpire: (key: string, milliseconds: number) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
2344
+ pexpire: (key: string, milliseconds: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
2037
2345
  /**
2038
2346
  * @see https://redis.io/commands/pexpireat
2039
2347
  */
2040
- pexpireat: (key: string, unix: number) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
2348
+ pexpireat: (key: string, unix: number, option?: ExpireOption | undefined) => Pipeline<[...TCommands, Command<any, 0 | 1>]>;
2041
2349
  /**
2042
2350
  * @see https://redis.io/commands/pfadd
2043
2351
  */
@@ -2459,6 +2767,10 @@ declare class Pipeline<TCommands extends Command<any, any>[] = []> {
2459
2767
  * @see https://redis.io/commands/json.get
2460
2768
  */
2461
2769
  get: (...args: CommandArgs<typeof JsonGetCommand>) => Pipeline<[...TCommands, Command<any, any>]>;
2770
+ /**
2771
+ * @see https://redis.io/commands/json.merge
2772
+ */
2773
+ merge: (key: string, path: string, value: string | number | unknown[] | Record<string, unknown>) => Pipeline<[...TCommands, Command<any, "OK" | null>]>;
2462
2774
  /**
2463
2775
  * @see https://redis.io/commands/json.mget
2464
2776
  */
@@ -2558,6 +2870,48 @@ declare class Script<TResult = unknown> {
2558
2870
  private digest;
2559
2871
  }
2560
2872
 
2873
+ /**
2874
+ * Creates a new script.
2875
+ *
2876
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
2877
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
2878
+ * the entire script. Afterwards, the script is cached on the server.
2879
+ *
2880
+ * @example
2881
+ * ```ts
2882
+ * const redis = new Redis({...})
2883
+ *
2884
+ * const script = redis.createScript<string>("return ARGV[1];", { readOnly: true })
2885
+ * const arg1 = await script.evalRo([], ["Hello World"])
2886
+ * expect(arg1, "Hello World")
2887
+ * ```
2888
+ */
2889
+ declare class ScriptRO<TResult = unknown> {
2890
+ readonly script: string;
2891
+ readonly sha1: string;
2892
+ private readonly redis;
2893
+ constructor(redis: Redis, script: string);
2894
+ /**
2895
+ * Send an `EVAL_RO` command to redis.
2896
+ */
2897
+ evalRo(keys: string[], args: string[]): Promise<TResult>;
2898
+ /**
2899
+ * Calculates the sha1 hash of the script and then calls `EVALSHA_RO`.
2900
+ */
2901
+ evalshaRo(keys: string[], args: string[]): Promise<TResult>;
2902
+ /**
2903
+ * Optimistically try to run `EVALSHA_RO` first.
2904
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL_RO`.
2905
+ *
2906
+ * Following calls will be able to use the cached script
2907
+ */
2908
+ exec(keys: string[], args: string[]): Promise<TResult>;
2909
+ /**
2910
+ * Compute the sha1 hash of the script and return its hex representation.
2911
+ */
2912
+ private digest;
2913
+ }
2914
+
2561
2915
  /**
2562
2916
  * Serverless redis client for upstash.
2563
2917
  */
@@ -2621,6 +2975,10 @@ declare class Redis {
2621
2975
  * @see https://redis.io/commands/json.get
2622
2976
  */
2623
2977
  get: <TData>(...args: CommandArgs<typeof JsonGetCommand>) => Promise<TData | null>;
2978
+ /**
2979
+ * @see https://redis.io/commands/json.merge
2980
+ */
2981
+ merge: (key: string, path: string, value: string | number | unknown[] | Record<string, unknown>) => Promise<"OK" | null>;
2624
2982
  /**
2625
2983
  * @see https://redis.io/commands/json.mget
2626
2984
  */
@@ -2684,7 +3042,37 @@ declare class Redis {
2684
3042
  * Technically this is not private, we can hide it from intellisense by doing this
2685
3043
  */
2686
3044
  protected addTelemetry: (telemetry: Telemetry) => void;
2687
- createScript(script: string): Script;
3045
+ /**
3046
+ * Creates a new script.
3047
+ *
3048
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
3049
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
3050
+ * the entire script. Afterwards, the script is cached on the server.
3051
+ *
3052
+ * @param script - The script to create
3053
+ * @param opts - Optional options to pass to the script `{ readonly?: boolean }`
3054
+ * @returns A new script
3055
+ *
3056
+ * @example
3057
+ * ```ts
3058
+ * const redis = new Redis({...})
3059
+ *
3060
+ * const script = redis.createScript<string>("return ARGV[1];")
3061
+ * const arg1 = await script.eval([], ["Hello World"])
3062
+ * expect(arg1, "Hello World")
3063
+ * ```
3064
+ * @example
3065
+ * ```ts
3066
+ * const redis = new Redis({...})
3067
+ *
3068
+ * const script = redis.createScript<string>("return ARGV[1];", { readonly: true })
3069
+ * const arg1 = await script.evalRo([], ["Hello World"])
3070
+ * expect(arg1, "Hello World")
3071
+ * ```
3072
+ */
3073
+ createScript<TResult = unknown, TReadonly extends boolean = false>(script: string, opts?: {
3074
+ readonly?: TReadonly;
3075
+ }): TReadonly extends true ? ScriptRO<TResult> : Script<TResult>;
2688
3076
  /**
2689
3077
  * Create a new pipeline that allows you to send requests in bulk.
2690
3078
  *
@@ -2763,14 +3151,26 @@ declare class Redis {
2763
3151
  * @see https://redis.io/commands/echo
2764
3152
  */
2765
3153
  echo: (message: string) => Promise<string>;
3154
+ /**
3155
+ * @see https://redis.io/commands/eval_ro
3156
+ */
3157
+ evalRo: <TArgs extends unknown[], TData = unknown>(script: string, keys: string[], args: TArgs) => Promise<TData>;
2766
3158
  /**
2767
3159
  * @see https://redis.io/commands/eval
2768
3160
  */
2769
3161
  eval: <TArgs extends unknown[], TData = unknown>(script: string, keys: string[], args: TArgs) => Promise<TData>;
3162
+ /**
3163
+ * @see https://redis.io/commands/evalsha_ro
3164
+ */
3165
+ evalshaRo: <TArgs extends unknown[], TData = unknown>(sha1: string, keys: string[], args: TArgs) => Promise<TData>;
2770
3166
  /**
2771
3167
  * @see https://redis.io/commands/evalsha
2772
3168
  */
2773
3169
  evalsha: <TArgs extends unknown[], TData = unknown>(sha1: string, keys: string[], args: TArgs) => Promise<TData>;
3170
+ /**
3171
+ * Generic method to execute any Redis command.
3172
+ */
3173
+ exec: <TResult>(args: [command: string, ...args: (string | number | boolean)[]]) => Promise<TResult>;
2774
3174
  /**
2775
3175
  * @see https://redis.io/commands/exists
2776
3176
  */
@@ -2778,11 +3178,11 @@ declare class Redis {
2778
3178
  /**
2779
3179
  * @see https://redis.io/commands/expire
2780
3180
  */
2781
- expire: (key: string, seconds: number, option?: ("NX" | "nx" | "XX" | "xx" | "GT" | "gt" | "LT" | "lt") | undefined) => Promise<0 | 1>;
3181
+ expire: (key: string, seconds: number, option?: ExpireOption | undefined) => Promise<0 | 1>;
2782
3182
  /**
2783
3183
  * @see https://redis.io/commands/expireat
2784
3184
  */
2785
- expireat: (key: string, unix: number) => Promise<0 | 1>;
3185
+ expireat: (key: string, unix: number, option?: ExpireOption | undefined) => Promise<0 | 1>;
2786
3186
  /**
2787
3187
  * @see https://redis.io/commands/flushall
2788
3188
  */
@@ -2895,6 +3295,46 @@ declare class Redis {
2895
3295
  * @see https://redis.io/commands/getdel
2896
3296
  */
2897
3297
  getdel: <TData>(key: string) => Promise<TData | null>;
3298
+ /**
3299
+ * @see https://redis.io/commands/getex
3300
+ */
3301
+ getex: <TData>(key: string, opts?: ({
3302
+ ex: number;
3303
+ px?: never;
3304
+ exat?: never;
3305
+ pxat?: never;
3306
+ persist?: never;
3307
+ } | {
3308
+ ex?: never;
3309
+ px: number;
3310
+ exat?: never;
3311
+ pxat?: never;
3312
+ persist?: never;
3313
+ } | {
3314
+ ex?: never;
3315
+ px?: never;
3316
+ exat: number;
3317
+ pxat?: never;
3318
+ persist?: never;
3319
+ } | {
3320
+ ex?: never;
3321
+ px?: never;
3322
+ exat?: never;
3323
+ pxat: number;
3324
+ persist?: never;
3325
+ } | {
3326
+ ex?: never;
3327
+ px?: never;
3328
+ exat?: never;
3329
+ pxat?: never;
3330
+ persist: true;
3331
+ } | {
3332
+ ex?: never;
3333
+ px?: never;
3334
+ exat?: never;
3335
+ pxat?: never;
3336
+ persist?: never;
3337
+ }) | undefined) => Promise<TData | null>;
2898
3338
  /**
2899
3339
  * @see https://redis.io/commands/getrange
2900
3340
  */
@@ -2911,6 +3351,42 @@ declare class Redis {
2911
3351
  * @see https://redis.io/commands/hexists
2912
3352
  */
2913
3353
  hexists: (key: string, field: string) => Promise<number>;
3354
+ /**
3355
+ * @see https://redis.io/commands/hexpire
3356
+ */
3357
+ hexpire: (key: string, fields: string | number | (string | number)[], seconds: number, option?: ExpireOption | undefined) => Promise<(0 | 1 | 2 | -2)[]>;
3358
+ /**
3359
+ * @see https://redis.io/commands/hexpireat
3360
+ */
3361
+ hexpireat: (key: string, fields: string | number | (string | number)[], timestamp: number, option?: ExpireOption | undefined) => Promise<(0 | 1 | 2 | -2)[]>;
3362
+ /**
3363
+ * @see https://redis.io/commands/hexpiretime
3364
+ */
3365
+ hexpiretime: (key: string, fields: string | number | (string | number)[]) => Promise<number[]>;
3366
+ /**
3367
+ * @see https://redis.io/commands/httl
3368
+ */
3369
+ httl: (key: string, fields: string | number | (string | number)[]) => Promise<number[]>;
3370
+ /**
3371
+ * @see https://redis.io/commands/hpexpire
3372
+ */
3373
+ hpexpire: (key: string, fields: string | number | (string | number)[], milliseconds: number, option?: ExpireOption | undefined) => Promise<(0 | 1 | 2 | -2)[]>;
3374
+ /**
3375
+ * @see https://redis.io/commands/hpexpireat
3376
+ */
3377
+ hpexpireat: (key: string, fields: string | number | (string | number)[], timestamp: number, option?: ExpireOption | undefined) => Promise<(0 | 1 | 2 | -2)[]>;
3378
+ /**
3379
+ * @see https://redis.io/commands/hpexpiretime
3380
+ */
3381
+ hpexpiretime: (key: string, fields: string | number | (string | number)[]) => Promise<number[]>;
3382
+ /**
3383
+ * @see https://redis.io/commands/hpttl
3384
+ */
3385
+ hpttl: (key: string, fields: string | number | (string | number)[]) => Promise<number[]>;
3386
+ /**
3387
+ * @see https://redis.io/commands/hpersist
3388
+ */
3389
+ hpersist: (key: string, fields: string | number | (string | number)[]) => Promise<(1 | -2 | -1)[]>;
2914
3390
  /**
2915
3391
  * @see https://redis.io/commands/hget
2916
3392
  */
@@ -3062,11 +3538,11 @@ declare class Redis {
3062
3538
  /**
3063
3539
  * @see https://redis.io/commands/pexpire
3064
3540
  */
3065
- pexpire: (key: string, milliseconds: number) => Promise<0 | 1>;
3541
+ pexpire: (key: string, milliseconds: number, option?: ExpireOption | undefined) => Promise<0 | 1>;
3066
3542
  /**
3067
3543
  * @see https://redis.io/commands/pexpireat
3068
3544
  */
3069
- pexpireat: (key: string, unix: number) => Promise<0 | 1>;
3545
+ pexpireat: (key: string, unix: number, option?: ExpireOption | undefined) => Promise<0 | 1>;
3070
3546
  /**
3071
3547
  * @see https://redis.io/commands/pfadd
3072
3548
  */
@@ -3087,6 +3563,10 @@ declare class Redis {
3087
3563
  * @see https://redis.io/commands/psetex
3088
3564
  */
3089
3565
  psetex: <TData>(key: string, ttl: number, value: TData) => Promise<string>;
3566
+ /**
3567
+ * @see https://redis.io/commands/psubscribe
3568
+ */
3569
+ psubscribe: <TMessage>(patterns: string | string[]) => Subscriber<TMessage>;
3090
3570
  /**
3091
3571
  * @see https://redis.io/commands/pttl
3092
3572
  */
@@ -3215,6 +3695,10 @@ declare class Redis {
3215
3695
  * @see https://redis.io/commands/strlen
3216
3696
  */
3217
3697
  strlen: (key: string) => Promise<number>;
3698
+ /**
3699
+ * @see https://redis.io/commands/subscribe
3700
+ */
3701
+ subscribe: <TMessage>(channels: string | string[]) => Subscriber<TMessage>;
3218
3702
  /**
3219
3703
  * @see https://redis.io/commands/sunion
3220
3704
  */
@@ -3485,4 +3969,4 @@ declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] |
3485
3969
  constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
3486
3970
  }
3487
3971
 
3488
- export { HValsCommand as $, AppendCommand as A, BitCountCommand as B, CopyCommand as C, DBSizeCommand as D, EchoCommand as E, FlushAllCommand as F, GeoAddCommand as G, GetRangeCommand as H, GetSetCommand as I, HDelCommand as J, HExistsCommand as K, HGetCommand as L, HGetAllCommand as M, HIncrByCommand as N, HIncrByFloatCommand as O, Pipeline as P, HKeysCommand as Q, type RedisOptions as R, HLenCommand as S, HMGetCommand as T, type UpstashRequest as U, HMSetCommand as V, HRandFieldCommand as W, HScanCommand as X, HSetCommand as Y, HSetNXCommand as Z, HStrLenCommand as _, type RequesterConfig as a, SetBitCommand as a$, IncrCommand as a0, IncrByCommand as a1, IncrByFloatCommand as a2, JsonArrAppendCommand as a3, JsonArrIndexCommand as a4, JsonArrInsertCommand as a5, JsonArrLenCommand as a6, JsonArrPopCommand as a7, JsonArrTrimCommand as a8, JsonClearCommand as a9, MGetCommand as aA, MSetCommand as aB, MSetNXCommand as aC, PersistCommand as aD, PExpireCommand as aE, PExpireAtCommand as aF, PingCommand as aG, PSetEXCommand as aH, PTtlCommand as aI, PublishCommand as aJ, RandomKeyCommand as aK, RenameCommand as aL, RenameNXCommand as aM, RPopCommand as aN, RPushCommand as aO, RPushXCommand as aP, SAddCommand as aQ, ScanCommand as aR, type ScanCommandOptions as aS, SCardCommand as aT, ScriptExistsCommand as aU, ScriptFlushCommand as aV, ScriptLoadCommand as aW, SDiffCommand as aX, SDiffStoreCommand as aY, SetCommand as aZ, type SetCommandOptions as a_, JsonDelCommand as aa, JsonForgetCommand as ab, JsonGetCommand as ac, JsonMGetCommand as ad, JsonNumIncrByCommand as ae, JsonNumMultByCommand as af, JsonObjKeysCommand as ag, JsonObjLenCommand as ah, JsonRespCommand as ai, JsonSetCommand as aj, JsonStrAppendCommand as ak, JsonStrLenCommand as al, JsonToggleCommand as am, JsonTypeCommand as an, KeysCommand as ao, LIndexCommand as ap, LInsertCommand as aq, LLenCommand as ar, LMoveCommand as as, LPopCommand as at, LPushCommand as au, LPushXCommand as av, LRangeCommand as aw, LRemCommand as ax, LSetCommand as ay, LTrimCommand as az, Redis as b, SetExCommand as b0, SetNxCommand as b1, SetRangeCommand as b2, SInterCommand as b3, SInterStoreCommand as b4, SIsMemberCommand as b5, SMembersCommand as b6, SMIsMemberCommand as b7, SMoveCommand as b8, SPopCommand as b9, ZPopMinCommand as bA, ZRangeCommand as bB, type ZRangeCommandOptions as bC, ZRankCommand as bD, ZRemCommand as bE, ZRemRangeByLexCommand as bF, ZRemRangeByRankCommand as bG, ZRemRangeByScoreCommand as bH, ZRevRankCommand as bI, ZScanCommand as bJ, ZScoreCommand as bK, ZUnionCommand as bL, type ZUnionCommandOptions as bM, ZUnionStoreCommand as bN, type ZUnionStoreCommandOptions as bO, SRandMemberCommand as ba, SRemCommand as bb, SScanCommand as bc, StrLenCommand as bd, SUnionCommand as be, SUnionStoreCommand as bf, TimeCommand as bg, TouchCommand as bh, TtlCommand as bi, type Type as bj, TypeCommand as bk, UnlinkCommand as bl, XAddCommand as bm, XRangeCommand as bn, type ScoreMember as bo, type ZAddCommandOptions as bp, ZAddCommand as bq, ZCardCommand as br, ZCountCommand as bs, ZDiffStoreCommand as bt, ZIncrByCommand as bu, ZInterStoreCommand as bv, type ZInterStoreCommandOptions as bw, ZLexCountCommand as bx, ZMScoreCommand as by, ZPopMaxCommand as bz, type UpstashResponse as c, type Requester as d, error as e, BitOpCommand as f, BitPosCommand as g, DecrCommand as h, DecrByCommand as i, DelCommand as j, EvalCommand as k, EvalshaCommand as l, ExistsCommand as m, ExpireCommand as n, ExpireAtCommand as o, FlushDBCommand as p, type GeoAddCommandOptions as q, type GeoMember as r, GeoDistCommand as s, GeoHashCommand as t, GeoPosCommand as u, GeoSearchCommand as v, GeoSearchStoreCommand as w, GetCommand as x, GetBitCommand as y, GetDelCommand as z };
3972
+ export { HGetCommand as $, AppendCommand as A, BitCountCommand as B, CopyCommand as C, DBSizeCommand as D, EchoCommand as E, FlushAllCommand as F, GeoAddCommand as G, GetCommand as H, GetBitCommand as I, GetDelCommand as J, GetExCommand as K, GetRangeCommand as L, GetSetCommand as M, HDelCommand as N, HExistsCommand as O, Pipeline as P, HExpireCommand as Q, type RedisOptions as R, HExpireAtCommand as S, HExpireTimeCommand as T, type UpstashRequest as U, HTtlCommand as V, HPExpireCommand as W, HPExpireAtCommand as X, HPExpireTimeCommand as Y, HPTtlCommand as Z, HPersistCommand as _, type RequesterConfig as a, RPopCommand as a$, HGetAllCommand as a0, HIncrByCommand as a1, HIncrByFloatCommand as a2, HKeysCommand as a3, HLenCommand as a4, HMGetCommand as a5, HMSetCommand as a6, HRandFieldCommand as a7, HScanCommand as a8, HSetCommand as a9, JsonToggleCommand as aA, JsonTypeCommand as aB, KeysCommand as aC, LIndexCommand as aD, LInsertCommand as aE, LLenCommand as aF, LMoveCommand as aG, LPopCommand as aH, LPushCommand as aI, LPushXCommand as aJ, LRangeCommand as aK, LRemCommand as aL, LSetCommand as aM, LTrimCommand as aN, MGetCommand as aO, MSetCommand as aP, MSetNXCommand as aQ, PersistCommand as aR, PExpireCommand as aS, PExpireAtCommand as aT, PingCommand as aU, PSetEXCommand as aV, PTtlCommand as aW, PublishCommand as aX, RandomKeyCommand as aY, RenameCommand as aZ, RenameNXCommand as a_, HSetNXCommand as aa, HStrLenCommand as ab, HValsCommand as ac, IncrCommand as ad, IncrByCommand as ae, IncrByFloatCommand as af, JsonArrAppendCommand as ag, JsonArrIndexCommand as ah, JsonArrInsertCommand as ai, JsonArrLenCommand as aj, JsonArrPopCommand as ak, JsonArrTrimCommand as al, JsonClearCommand as am, JsonDelCommand as an, JsonForgetCommand as ao, JsonGetCommand as ap, JsonMergeCommand as aq, JsonMGetCommand as ar, JsonNumIncrByCommand as as, JsonNumMultByCommand as at, JsonObjKeysCommand as au, JsonObjLenCommand as av, JsonRespCommand as aw, JsonSetCommand as ax, JsonStrAppendCommand as ay, JsonStrLenCommand as az, Redis as b, ZUnionStoreCommand as b$, RPushCommand as b0, RPushXCommand as b1, SAddCommand as b2, ScanCommand as b3, type ScanCommandOptions as b4, SCardCommand as b5, ScriptExistsCommand as b6, ScriptFlushCommand as b7, ScriptLoadCommand as b8, SDiffCommand as b9, XAddCommand as bA, XRangeCommand as bB, type ScoreMember as bC, type ZAddCommandOptions as bD, ZAddCommand as bE, ZCardCommand as bF, ZCountCommand as bG, ZDiffStoreCommand as bH, ZIncrByCommand as bI, ZInterStoreCommand as bJ, type ZInterStoreCommandOptions as bK, ZLexCountCommand as bL, ZMScoreCommand as bM, ZPopMaxCommand as bN, ZPopMinCommand as bO, ZRangeCommand as bP, type ZRangeCommandOptions as bQ, ZRankCommand as bR, ZRemCommand as bS, ZRemRangeByLexCommand as bT, ZRemRangeByRankCommand as bU, ZRemRangeByScoreCommand as bV, ZRevRankCommand as bW, ZScanCommand as bX, ZScoreCommand as bY, ZUnionCommand as bZ, type ZUnionCommandOptions as b_, SDiffStoreCommand as ba, SetCommand as bb, type SetCommandOptions as bc, SetBitCommand as bd, SetExCommand as be, SetNxCommand as bf, SetRangeCommand as bg, SInterCommand as bh, SInterStoreCommand as bi, SIsMemberCommand as bj, SMembersCommand as bk, SMIsMemberCommand as bl, SMoveCommand as bm, SPopCommand as bn, SRandMemberCommand as bo, SRemCommand as bp, SScanCommand as bq, StrLenCommand as br, SUnionCommand as bs, SUnionStoreCommand as bt, TimeCommand as bu, TouchCommand as bv, TtlCommand as bw, type Type as bx, TypeCommand as by, UnlinkCommand as bz, type UpstashResponse as c, type ZUnionStoreCommandOptions as c0, type Requester as d, error as e, BitOpCommand as f, BitPosCommand as g, DecrCommand as h, DecrByCommand as i, DelCommand as j, EvalROCommand as k, EvalCommand as l, EvalshaROCommand as m, EvalshaCommand as n, ExistsCommand as o, ExpireCommand as p, type ExpireOption as q, ExpireAtCommand as r, FlushDBCommand as s, type GeoAddCommandOptions as t, type GeoMember as u, GeoDistCommand as v, GeoHashCommand as w, GeoPosCommand as x, GeoSearchCommand as y, GeoSearchStoreCommand as z };