@sebspark/promise-cache 3.5.0 → 3.7.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.
package/dist/index.d.ts CHANGED
@@ -102,6 +102,9 @@ declare class PromiseCache<U> {
102
102
  wrap(key: string, delegate: () => Promise<U>, ttlInSeconds?: number, ttlKeyInSeconds?: string): Promise<U>;
103
103
  }
104
104
 
105
+ type Client = ReturnType<typeof createClient>;
106
+ type Multi = ReturnType<Client['multi']>;
107
+ type MultiExecReturnTypes = Awaited<ReturnType<Multi['exec']>>[number] | boolean;
105
108
  /**
106
109
  * Defines the expiration strategy for cached values.
107
110
  *
@@ -149,45 +152,406 @@ type Cache = {
149
152
  */
150
153
  wrap: <A extends unknown[], R>(delegate: (...args: A) => Promise<R>, options: CachingOptions<A, R>) => (...args: A) => Promise<R>;
151
154
  };
155
+ /**
156
+ * Interface for a key-value storage system that supports Redis-like commands.
157
+ * Provides methods for storing, retrieving, and managing data with optional expiration.
158
+ */
152
159
  interface IPersistor {
153
160
  /**
154
161
  * Stores a value in Redis or Memory with an optional expiration.
155
162
  * @param key - The storage key.
156
163
  * @param value - The string value to store.
157
- * @param options - Expiration options.
158
- * @returns Resolves to `"OK"` if successful.
164
+ * @param options - Expiration options (TTL, absolute expiration, etc.).
165
+ * @returns Resolves to `"OK"` if successful, otherwise `null` if the operation fails.
159
166
  */
160
167
  set: (key: string, value: string, options?: SetOptions) => Promise<string | null>;
161
168
  /**
162
169
  * Retrieves a value from Redis or Memory.
163
170
  * @param key - The storage key.
164
- * @returns Resolves to the stored value or `null` if not found.
171
+ * @returns Resolves to the stored value as a string, or `null` if the key does not exist.
165
172
  */
166
173
  get: (key: string) => Promise<string | null>;
167
174
  /**
168
175
  * Deletes a key from Redis or Memory.
169
176
  * @param key - The storage key.
170
- * @returns Resolves to the number of keys removed (1 if deleted, 0 if not found).
177
+ * @returns Resolves to the number of keys removed (`1` if deleted, `0` if the key was not found).
171
178
  */
172
179
  del: (key: string) => Promise<number>;
173
180
  /**
174
181
  * Sets a time-to-live (TTL) in seconds for a key.
175
182
  * @param key - The storage key.
176
183
  * @param seconds - TTL in seconds.
177
- * @returns Resolves to true if successful, false if key does not exist.
184
+ * @returns Resolves to `true` if the expiration was successfully set, `false` if the key does not exist.
178
185
  */
179
186
  expire: (key: string, seconds: number) => Promise<boolean>;
180
187
  /**
181
- * Gets the remaining TTL of a key in seconds.
188
+ * Gets the remaining TTL (time-to-live) of a key.
182
189
  * @param key - The storage key.
183
- * @returns Remaining TTL in seconds, `-1` if no TTL is set, or `-2` if key does not exist.
190
+ * @returns
191
+ * - The remaining TTL in seconds.
192
+ * - `-1` if the key exists but has no expiration.
193
+ * - `-2` if the key does not exist.
184
194
  */
185
195
  ttl: (key: string) => Promise<number>;
186
196
  /**
187
- * Clears all keys in Redis or Memory.
188
- * @returns Resolves to `"OK"` when complete.
197
+ * Clears all keys from the storage system.
198
+ * @returns Resolves to `"OK"` when the operation completes successfully.
189
199
  */
190
200
  flushAll: () => Promise<string>;
201
+ /**
202
+ * Stores a value and sets an expiration time in seconds.
203
+ * @param key - The storage key.
204
+ * @param seconds - Expiration time in seconds.
205
+ * @param value - The string value to store.
206
+ * @returns Resolves to `"OK"` if successful, otherwise `null` if the operation fails.
207
+ */
208
+ setEx: (key: string, seconds: number, value: string) => Promise<string | null>;
209
+ /**
210
+ * Stores a value and sets an expiration time in milliseconds.
211
+ * @param key - The storage key.
212
+ * @param milliseconds - Expiration time in milliseconds.
213
+ * @param value - The string value to store.
214
+ * @returns Resolves to `"OK"` if successful, otherwise `null` if the operation fails.
215
+ */
216
+ pSetEx: (key: string, milliseconds: number, value: string) => Promise<string | null>;
217
+ /**
218
+ * Stores a value **only if the key does not already exist**.
219
+ * @param key - The storage key.
220
+ * @param value - The string value to store.
221
+ * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
222
+ */
223
+ setNX: (key: string, value: string) => Promise<boolean>;
224
+ /**
225
+ * Creates a multi-command batch operation.
226
+ * This allows multiple commands to be executed in a batch, improving performance.
227
+ * @returns An instance of `IPersistorMulti` to queue multiple commands.
228
+ */
229
+ multi: () => IPersistorMulti;
230
+ /**
231
+ * Checks if keys exist in storage.
232
+ * @param keys - One or more keys to check.
233
+ * @returns Resolves to the number of keys that exist.
234
+ */
235
+ exists: (key: string | string[]) => Promise<number>;
236
+ /**
237
+ * Increments a key by 1.
238
+ * @param key - The key to increment.
239
+ * @returns Resolves to the new value after increment.
240
+ */
241
+ incr: (key: string) => Promise<number>;
242
+ /**
243
+ * Decrements a key by 1.
244
+ * @param key - The key to decrement.
245
+ * @returns Resolves to the new value after decrement.
246
+ */
247
+ decr: (key: string) => Promise<number>;
248
+ /**
249
+ * Increments a key by a specified amount.
250
+ * @param key - The key to increment.
251
+ * @param increment - The amount to increase by.
252
+ * @returns Resolves to the new value after increment.
253
+ */
254
+ incrBy: (key: string, increment: number) => Promise<number>;
255
+ /**
256
+ * Decrements a key by a specified amount.
257
+ * @param key - The key to decrement.
258
+ * @param decrement - The amount to decrease by.
259
+ * @returns Resolves to the new value after decrement.
260
+ */
261
+ decrBy: (key: string, decrement: number) => Promise<number>;
262
+ /**
263
+ * Sets a field in a hash.
264
+ * @param key - The hash key.
265
+ * @param field - The field name.
266
+ * @param value - The value to store.
267
+ * @returns Resolves to `1` if the field was added, or `0` if updated.
268
+ */
269
+ hSet: (key: string, field: string, value: string) => Promise<number>;
270
+ /**
271
+ * Retrieves a field from a hash.
272
+ * @param key - The hash key.
273
+ * @param field - The field name.
274
+ * @returns Resolves to the value, or `undefined` if the field does not exist.
275
+ */
276
+ hGet: (key: string, field: string) => Promise<string | undefined>;
277
+ /**
278
+ * Pushes values to the left (head) of a list.
279
+ * @param key - The list key.
280
+ * @param values - The values to add.
281
+ * @returns Resolves to the length of the list after the operation.
282
+ */
283
+ lPush: (key: string, values: string | string[]) => Promise<number>;
284
+ /**
285
+ * Pushes values to the right (tail) of a list.
286
+ * @param key - The list key.
287
+ * @param values - The values to add.
288
+ * @returns Resolves to the length of the list after the operation.
289
+ */
290
+ rPush: (key: string, values: string | string[]) => Promise<number>;
291
+ /**
292
+ * Removes and returns the first element from a list.
293
+ * @param key - The list key.
294
+ * @returns Resolves to the removed element, or `null` if the list is empty.
295
+ */
296
+ lPop: (key: string) => Promise<string | null>;
297
+ /**
298
+ * Removes and returns the last element from a list.
299
+ * @param key - The list key.
300
+ * @returns Resolves to the removed element, or `null` if the list is empty.
301
+ */
302
+ rPop: (key: string) => Promise<string | null>;
303
+ /**
304
+ * Retrieves a range of elements from a list.
305
+ * @param key - The list key.
306
+ * @param start - The start index.
307
+ * @param stop - The stop index (inclusive).
308
+ * @returns Resolves to an array of elements in the range.
309
+ */
310
+ lRange: (key: string, start: number, stop: number) => Promise<string[]>;
311
+ /**
312
+ * Adds members to a set.
313
+ * @param key - The set key.
314
+ * @param values - The values to add.
315
+ * @returns Resolves to the number of elements successfully added.
316
+ */
317
+ sAdd: (key: string, values: string | string[]) => Promise<number>;
318
+ /**
319
+ * Removes members from a set.
320
+ * @param key - The set key.
321
+ * @param values - The values to remove.
322
+ * @returns Resolves to the number of elements removed.
323
+ */
324
+ sRem: (key: string, values: string | string[]) => Promise<number>;
325
+ /**
326
+ * Retrieves all members of a set.
327
+ * @param key - The set key.
328
+ * @returns Resolves to an array of all members in the set.
329
+ */
330
+ sMembers: (key: string) => Promise<string[]>;
331
+ /**
332
+ * Adds members to a sorted set with scores.
333
+ * @param key - The sorted set key.
334
+ * @param members - An array of objects with `score` and `value`.
335
+ * @returns Resolves to the number of elements successfully added.
336
+ */
337
+ zAdd: (key: string, members: {
338
+ score: number;
339
+ value: string;
340
+ }[]) => Promise<number>;
341
+ /**
342
+ * Retrieves a range of members from a sorted set.
343
+ * @param key - The sorted set key.
344
+ * @param start - The start index.
345
+ * @param stop - The stop index (inclusive).
346
+ * @returns Resolves to an array of member values in the range.
347
+ */
348
+ zRange: (key: string, start: number, stop: number) => Promise<string[]>;
349
+ /**
350
+ * Removes members from a sorted set.
351
+ * @param key - The sorted set key.
352
+ * @param members - The members to remove.
353
+ * @returns Resolves to the number of elements removed.
354
+ */
355
+ zRem: (key: string, members: string | string[]) => Promise<number>;
356
+ }
357
+ /**
358
+ * Interface for executing multiple storage commands in a batch operation.
359
+ * All commands are queued and executed when `exec()` is called.
360
+ */
361
+ interface IPersistorMulti {
362
+ /**
363
+ * Stores a value in Redis or Memory with an optional expiration.
364
+ * @param key - The storage key.
365
+ * @param value - The string value to store.
366
+ * @param options - Expiration options (TTL, absolute expiration, etc.).
367
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
368
+ */
369
+ set: (key: string, value: string, options?: SetOptions) => IPersistorMulti;
370
+ /**
371
+ * Stores a value and sets an expiration time in seconds.
372
+ * @param key - The storage key.
373
+ * @param seconds - Expiration time in seconds.
374
+ * @param value - The string value to store.
375
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
376
+ */
377
+ setEx: (key: string, seconds: number, value: string) => IPersistorMulti;
378
+ /**
379
+ * Stores a value and sets an expiration time in milliseconds.
380
+ * @param key - The storage key.
381
+ * @param milliseconds - Expiration time in milliseconds.
382
+ * @param value - The string value to store.
383
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
384
+ */
385
+ pSetEx: (key: string, milliseconds: number, value: string) => IPersistorMulti;
386
+ /**
387
+ * Stores a value **only if the key does not already exist**.
388
+ * @param key - The storage key.
389
+ * @param value - The string value to store.
390
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
391
+ */
392
+ setNX: (key: string, value: string) => IPersistorMulti;
393
+ /**
394
+ * Retrieves a value from Redis or Memory.
395
+ * @param key - The storage key.
396
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
397
+ */
398
+ get: (key: string) => IPersistorMulti;
399
+ /**
400
+ * Deletes a key from Redis or Memory.
401
+ * @param key - The storage key.
402
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
403
+ */
404
+ del: (key: string) => IPersistorMulti;
405
+ /**
406
+ * Sets a time-to-live (TTL) in seconds for a key.
407
+ * @param key - The storage key.
408
+ * @param seconds - TTL in seconds.
409
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
410
+ */
411
+ expire: (key: string, seconds: number) => IPersistorMulti;
412
+ /**
413
+ * Gets the remaining TTL (time-to-live) of a key.
414
+ * @param key - The storage key.
415
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
416
+ */
417
+ ttl: (key: string) => IPersistorMulti;
418
+ /**
419
+ * Clears all keys from the storage system.
420
+ * @returns The same `IPersistorMulti` instance, enabling method chaining.
421
+ */
422
+ flushAll: () => IPersistorMulti;
423
+ /**
424
+ * Queues an `exists` operation in the transaction.
425
+ * @param key - The storage key or an array of keys.
426
+ * @returns The `IPersistorMulti` instance for method chaining.
427
+ */
428
+ exists: (key: string | string[]) => IPersistorMulti;
429
+ /**
430
+ * Queues an `incr` operation in the transaction.
431
+ * @param key - The storage key.
432
+ * @returns The `IPersistorMulti` instance for method chaining.
433
+ */
434
+ incr: (key: string) => IPersistorMulti;
435
+ /**
436
+ * Queues an `incrBy` operation in the transaction.
437
+ * @param key - The storage key.
438
+ * @param increment - The amount to increment by.
439
+ * @returns The `IPersistorMulti` instance for method chaining.
440
+ */
441
+ incrBy: (key: string, increment: number) => IPersistorMulti;
442
+ /**
443
+ * Queues a `decr` operation in the transaction.
444
+ * @param key - The storage key.
445
+ * @returns The `IPersistorMulti` instance for method chaining.
446
+ */
447
+ decr: (key: string) => IPersistorMulti;
448
+ /**
449
+ * Queues a `decrBy` operation in the transaction.
450
+ * @param key - The storage key.
451
+ * @param decrement - The amount to decrement by.
452
+ * @returns The `IPersistorMulti` instance for method chaining.
453
+ */
454
+ decrBy: (key: string, decrement: number) => IPersistorMulti;
455
+ /**
456
+ * Sets a field in a hash.
457
+ * @param key - The hash key.
458
+ * @param field - The field name.
459
+ * @param value - The value to store.
460
+ * @returns The multi-instance for chaining.
461
+ */
462
+ hSet: (key: string, field: string, value: string) => IPersistorMulti;
463
+ /**
464
+ * Retrieves a field from a hash.
465
+ * @param key - The hash key.
466
+ * @param field - The field name.
467
+ * @returns The multi-instance for chaining.
468
+ */
469
+ hGet: (key: string, field: string) => IPersistorMulti;
470
+ /**
471
+ * Pushes values to the left (head) of a list.
472
+ * @param key - The list key.
473
+ * @param values - The values to add.
474
+ * @returns The multi-instance for chaining.
475
+ */
476
+ lPush: (key: string, values: string | string[]) => IPersistorMulti;
477
+ /**
478
+ * Pushes values to the right (tail) of a list.
479
+ * @param key - The list key.
480
+ * @param values - The values to add.
481
+ * @returns The multi-instance for chaining.
482
+ */
483
+ rPush: (key: string, values: string | string[]) => IPersistorMulti;
484
+ /**
485
+ * Removes and returns the first element from a list.
486
+ * @param key - The list key.
487
+ * @returns The multi-instance for chaining.
488
+ */
489
+ lPop: (key: string) => IPersistorMulti;
490
+ /**
491
+ * Removes and returns the last element from a list.
492
+ * @param key - The list key.
493
+ * @returns The multi-instance for chaining.
494
+ */
495
+ rPop: (key: string) => IPersistorMulti;
496
+ /**
497
+ * Retrieves a range of elements from a list.
498
+ * @param key - The list key.
499
+ * @param start - The start index.
500
+ * @param stop - The stop index (inclusive).
501
+ * @returns The multi-instance for chaining.
502
+ */
503
+ lRange: (key: string, start: number, stop: number) => IPersistorMulti;
504
+ /**
505
+ * Adds members to a set.
506
+ * @param key - The set key.
507
+ * @param values - The values to add.
508
+ * @returns The multi-instance for chaining.
509
+ */
510
+ sAdd: (key: string, values: string | string[]) => IPersistorMulti;
511
+ /**
512
+ * Removes members from a set.
513
+ * @param key - The set key.
514
+ * @param values - The values to remove.
515
+ * @returns The multi-instance for chaining.
516
+ */
517
+ sRem: (key: string, values: string | string[]) => IPersistorMulti;
518
+ /**
519
+ * Retrieves all members of a set.
520
+ * @param key - The set key.
521
+ * @returns The multi-instance for chaining.
522
+ */
523
+ sMembers: (key: string) => IPersistorMulti;
524
+ /**
525
+ * Adds members to a sorted set with scores.
526
+ * @param key - The sorted set key.
527
+ * @param members - An array of objects with `score` and `value`.
528
+ * @returns The multi-instance for chaining.
529
+ */
530
+ zAdd: (key: string, members: {
531
+ score: number;
532
+ value: string;
533
+ }[]) => IPersistorMulti;
534
+ /**
535
+ * Retrieves a range of members from a sorted set.
536
+ * @param key - The sorted set key.
537
+ * @param start - The start index.
538
+ * @param stop - The stop index (inclusive).
539
+ * @returns The multi-instance for chaining.
540
+ */
541
+ zRange: (key: string, start: number, stop: number) => IPersistorMulti;
542
+ /**
543
+ * Removes members from a sorted set.
544
+ * @param key - The sorted set key.
545
+ * @param members - The members to remove.
546
+ * @returns The multi-instance for chaining.
547
+ */
548
+ zRem: (key: string, members: string | string[]) => IPersistorMulti;
549
+ /**
550
+ * Executes all queued commands and returns their results.
551
+ * @returns A promise resolving to an array of results for each command.
552
+ * The result type can be `string | number | boolean | null`, depending on the command.
553
+ */
554
+ exec: () => Promise<MultiExecReturnTypes[]>;
191
555
  }
192
556
 
193
557
  /**
@@ -236,6 +600,35 @@ declare class InMemoryPersistor implements IPersistor {
236
600
  * @returns {Promise<'OK' | null>} Resolves to `'OK'` on success, or `null` if a conditional set (`NX`) fails.
237
601
  */
238
602
  set(key: string, value: string, options?: SetOptions): Promise<'OK' | null>;
603
+ /**
604
+ * Stores a key-value pair with an expiration time in seconds.
605
+ * If the key already exists, it will be overwritten.
606
+ *
607
+ * @param key - The storage key.
608
+ * @param seconds - Expiration time in seconds.
609
+ * @param value - The string value to store.
610
+ * @returns Resolves to `'OK'` on success.
611
+ */
612
+ setEx(key: string, seconds: number, value: string): Promise<string | null>;
613
+ /**
614
+ * Stores a key-value pair with an expiration time in milliseconds.
615
+ * If the key already exists, it will be overwritten.
616
+ *
617
+ * @param key - The storage key.
618
+ * @param milliseconds - Expiration time in milliseconds.
619
+ * @param value - The string value to store.
620
+ * @returns Resolves to `'OK'` on success.
621
+ */
622
+ pSetEx(key: string, milliseconds: number, value: string): Promise<string | null>;
623
+ /**
624
+ * Stores a key-value pair **only if the key does not already exist**.
625
+ * If the key exists, the operation fails and returns `false`.
626
+ *
627
+ * @param key - The storage key.
628
+ * @param value - The string value to store.
629
+ * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
630
+ */
631
+ setNX(key: string, value: string): Promise<boolean>;
239
632
  /**
240
633
  * Retrieves the value associated with a key.
241
634
  *
@@ -270,12 +663,168 @@ declare class InMemoryPersistor implements IPersistor {
270
663
  * - `-2` if the key does not exist.
271
664
  */
272
665
  ttl(key: string): Promise<number>;
666
+ /**
667
+ * Checks if one or more keys exist in the store.
668
+ *
669
+ * @param {string | string[]} keys - A single key or an array of keys to check.
670
+ * @returns {Promise<number>} Resolves to the number of keys that exist.
671
+ */
672
+ exists(keys: string | string[]): Promise<number>;
673
+ /**
674
+ * Increments a numeric value stored at a key by 1.
675
+ * If the key does not exist, it is set to `1`.
676
+ *
677
+ * @param {string} key - The key to increment.
678
+ * @returns {Promise<number>} Resolves to the new value after increment.
679
+ */
680
+ incr(key: string): Promise<number>;
681
+ /**
682
+ * Increments a numeric value stored at a key by a specified amount.
683
+ * If the key does not exist, it is set to the increment value.
684
+ *
685
+ * @param {string} key - The key to increment.
686
+ * @param {number} increment - The amount to increase by.
687
+ * @returns {Promise<number>} Resolves to the new value after increment.
688
+ */
689
+ incrBy(key: string, increment: number): Promise<number>;
690
+ /**
691
+ * Decrements a numeric value stored at a key by 1.
692
+ * If the key does not exist, it is set to `-1`.
693
+ *
694
+ * @param {string} key - The key to decrement.
695
+ * @returns {Promise<number>} Resolves to the new value after decrement.
696
+ */
697
+ decr(key: string): Promise<number>;
698
+ /**
699
+ * Decrements a numeric value stored at a key by a specified amount.
700
+ * If the key does not exist, it is set to the negative decrement value.
701
+ *
702
+ * @param {string} key - The key to decrement.
703
+ * @param {number} decrement - The amount to decrease by.
704
+ * @returns {Promise<number>} Resolves to the new value after decrement.
705
+ */
706
+ decrBy(key: string, decrement: number): Promise<number>;
707
+ /**
708
+ * Sets a field in a hash.
709
+ * If the field already exists, its value is updated.
710
+ *
711
+ * @param key - The hash key.
712
+ * @param field - The field name.
713
+ * @param value - The value to store.
714
+ * @returns Resolves to `1` if a new field was added, `0` if an existing field was updated.
715
+ */
716
+ hSet(key: string, field: string, value: string): Promise<number>;
717
+ /**
718
+ * Retrieves a field from a hash.
719
+ *
720
+ * @param key - The hash key.
721
+ * @param field - The field name to retrieve.
722
+ * @returns Resolves to the field value, or `undefined` if the field does not exist.
723
+ */
724
+ hGet(key: string, field: string): Promise<string | undefined>;
725
+ /**
726
+ * Pushes elements to the left (head) of a list.
727
+ *
728
+ * @param key - The list key.
729
+ * @param values - One or more values to add.
730
+ * @returns Resolves to the length of the list after the operation.
731
+ */
732
+ lPush(key: string, values: string | string[]): Promise<number>;
733
+ /**
734
+ * Pushes elements to the right (tail) of a list.
735
+ *
736
+ * @param key - The list key.
737
+ * @param values - One or more values to add.
738
+ * @returns Resolves to the length of the list after the operation.
739
+ */
740
+ rPush(key: string, values: string | string[]): Promise<number>;
741
+ /**
742
+ * Removes and returns the first element from a list.
743
+ *
744
+ * @param key - The list key.
745
+ * @returns Resolves to the removed element, or `null` if the list is empty.
746
+ */
747
+ lPop(key: string): Promise<string | null>;
748
+ /**
749
+ * Removes and returns the last element from a list.
750
+ *
751
+ * @param key - The list key.
752
+ * @returns Resolves to the removed element, or `null` if the list is empty.
753
+ */
754
+ rPop(key: string): Promise<string | null>;
755
+ /**
756
+ * Retrieves a range of elements from a list.
757
+ *
758
+ * @param key - The list key.
759
+ * @param start - The starting index.
760
+ * @param stop - The stopping index.
761
+ * @returns Resolves to an array containing the requested range.
762
+ */
763
+ lRange(key: string, start: number, stop: number): Promise<string[]>;
764
+ /**
765
+ * Adds elements to a set.
766
+ *
767
+ * @param key - The set key.
768
+ * @param values - One or more values to add.
769
+ * @returns Resolves to the number of new elements added.
770
+ */
771
+ sAdd(key: string, values: string | string[]): Promise<number>;
772
+ /**
773
+ * Removes elements from a set.
774
+ *
775
+ * @param key - The set key.
776
+ * @param values - One or more values to remove.
777
+ * @returns Resolves to the number of elements removed.
778
+ */
779
+ sRem(key: string, values: string | string[]): Promise<number>;
780
+ /**
781
+ * Retrieves all elements from a set.
782
+ *
783
+ * @param key - The set key.
784
+ * @returns Resolves to an array of all set members.
785
+ */
786
+ sMembers(key: string): Promise<string[]>;
787
+ /**
788
+ * Adds members to a sorted set with scores.
789
+ *
790
+ * @param key - The sorted set key.
791
+ * @param members - An array of objects containing `{ score, value }`.
792
+ * @returns Resolves to the number of new elements added.
793
+ */
794
+ zAdd(key: string, members: {
795
+ score: number;
796
+ value: string;
797
+ }[]): Promise<number>;
798
+ /**
799
+ * Retrieves a range of elements from a sorted set.
800
+ *
801
+ * @param key - The sorted set key.
802
+ * @param start - The starting index.
803
+ * @param stop - The stopping index.
804
+ * @returns Resolves to an array of sorted set values in the range.
805
+ */
806
+ zRange(key: string, start: number, stop: number): Promise<string[]>;
807
+ /**
808
+ * Removes elements from a sorted set.
809
+ *
810
+ * @param key - The sorted set key.
811
+ * @param members - One or more values to remove.
812
+ * @returns Resolves to the number of elements removed.
813
+ */
814
+ zRem(key: string, members: string | string[]): Promise<number>;
273
815
  /**
274
816
  * Removes all keys from the store and clears all active expirations.
275
817
  *
276
818
  * @returns {Promise<'OK'>} Resolves to `'OK'` after all data is cleared.
277
819
  */
278
820
  flushAll(): Promise<'OK'>;
821
+ /**
822
+ * Creates a new multi-command batch instance.
823
+ * Commands queued in this batch will be executed together when `exec()` is called.
824
+ *
825
+ * @returns A new `IPersistorMulti` instance for batching commands.
826
+ */
827
+ multi(): IPersistorMulti;
279
828
  /**
280
829
  * Sets an expiration timeout for a key.
281
830
  * Cancels any existing expiration before setting a new one.
@@ -325,4 +874,13 @@ declare namespace time {
325
874
  export { time_DAY as DAY, time_HOUR as HOUR, time_MINUTE as MINUTE, time_SECOND as SECOND, time_WEEK as WEEK, time_add as add, time_days as days, time_hours as hours, time_minutes as minutes, time_seconds as seconds, time_sub as sub, time_today as today, time_tomorrow as tomorrow, time_weeks as weeks };
326
875
  }
327
876
 
328
- export { type Cache, type CachingOptions, type IPersistor, InMemoryPersistor, Persistor, type PersistorConstructorType, PromiseCache, type PromiseCacheOptions, createCache, time };
877
+ declare const serialize: <T>(data: T) => string;
878
+ declare const deserialize: <T>(serialized: string) => T;
879
+
880
+ declare const serializer_deserialize: typeof deserialize;
881
+ declare const serializer_serialize: typeof serialize;
882
+ declare namespace serializer {
883
+ export { serializer_deserialize as deserialize, serializer_serialize as serialize };
884
+ }
885
+
886
+ export { type Cache, type CachingOptions, type IPersistor, InMemoryPersistor, Persistor, type PersistorConstructorType, PromiseCache, type PromiseCacheOptions, createCache, serializer, time };