@sebspark/promise-cache 3.6.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.js CHANGED
@@ -483,6 +483,45 @@ var InMemoryPersistor = class {
483
483
  }
484
484
  return "OK";
485
485
  }
486
+ /**
487
+ * Stores a key-value pair with an expiration time in seconds.
488
+ * If the key already exists, it will be overwritten.
489
+ *
490
+ * @param key - The storage key.
491
+ * @param seconds - Expiration time in seconds.
492
+ * @param value - The string value to store.
493
+ * @returns Resolves to `'OK'` on success.
494
+ */
495
+ async setEx(key, seconds2, value) {
496
+ this.store.set(key, value);
497
+ await this.expire(key, seconds2);
498
+ return "OK";
499
+ }
500
+ /**
501
+ * Stores a key-value pair with an expiration time in milliseconds.
502
+ * If the key already exists, it will be overwritten.
503
+ *
504
+ * @param key - The storage key.
505
+ * @param milliseconds - Expiration time in milliseconds.
506
+ * @param value - The string value to store.
507
+ * @returns Resolves to `'OK'` on success.
508
+ */
509
+ async pSetEx(key, milliseconds, value) {
510
+ return this.setEx(key, milliseconds / 1e3, value);
511
+ }
512
+ /**
513
+ * Stores a key-value pair **only if the key does not already exist**.
514
+ * If the key exists, the operation fails and returns `false`.
515
+ *
516
+ * @param key - The storage key.
517
+ * @param value - The string value to store.
518
+ * @returns Resolves to `true` if the key was set, or `false` if the key already exists.
519
+ */
520
+ async setNX(key, value) {
521
+ if (this.store.has(key)) return false;
522
+ this.store.set(key, value);
523
+ return true;
524
+ }
486
525
  /**
487
526
  * Retrieves the value associated with a key.
488
527
  *
@@ -535,6 +574,283 @@ var InMemoryPersistor = class {
535
574
  const timeLeft = this.expiryTimestamps.get(key) - Date.now();
536
575
  return timeLeft > 0 ? Math.ceil(timeLeft / 1e3) : -2;
537
576
  }
577
+ /**
578
+ * Checks if one or more keys exist in the store.
579
+ *
580
+ * @param {string | string[]} keys - A single key or an array of keys to check.
581
+ * @returns {Promise<number>} Resolves to the number of keys that exist.
582
+ */
583
+ async exists(keys) {
584
+ const keyArray = Array.isArray(keys) ? keys : [keys];
585
+ return keyArray.reduce(
586
+ (count, key) => this.store.has(key) ? count + 1 : count,
587
+ 0
588
+ );
589
+ }
590
+ /**
591
+ * Increments a numeric value stored at a key by 1.
592
+ * If the key does not exist, it is set to `1`.
593
+ *
594
+ * @param {string} key - The key to increment.
595
+ * @returns {Promise<number>} Resolves to the new value after increment.
596
+ */
597
+ async incr(key) {
598
+ const current = Number(this.store.get(key)) || 0;
599
+ const newValue = current + 1;
600
+ this.store.set(key, newValue.toString());
601
+ return newValue;
602
+ }
603
+ /**
604
+ * Increments a numeric value stored at a key by a specified amount.
605
+ * If the key does not exist, it is set to the increment value.
606
+ *
607
+ * @param {string} key - The key to increment.
608
+ * @param {number} increment - The amount to increase by.
609
+ * @returns {Promise<number>} Resolves to the new value after increment.
610
+ */
611
+ async incrBy(key, increment) {
612
+ const current = Number(this.store.get(key)) || 0;
613
+ const newValue = current + increment;
614
+ this.store.set(key, newValue.toString());
615
+ return newValue;
616
+ }
617
+ /**
618
+ * Decrements a numeric value stored at a key by 1.
619
+ * If the key does not exist, it is set to `-1`.
620
+ *
621
+ * @param {string} key - The key to decrement.
622
+ * @returns {Promise<number>} Resolves to the new value after decrement.
623
+ */
624
+ async decr(key) {
625
+ const current = Number(this.store.get(key)) || 0;
626
+ const newValue = current - 1;
627
+ this.store.set(key, newValue.toString());
628
+ return newValue;
629
+ }
630
+ /**
631
+ * Decrements a numeric value stored at a key by a specified amount.
632
+ * If the key does not exist, it is set to the negative decrement value.
633
+ *
634
+ * @param {string} key - The key to decrement.
635
+ * @param {number} decrement - The amount to decrease by.
636
+ * @returns {Promise<number>} Resolves to the new value after decrement.
637
+ */
638
+ async decrBy(key, decrement) {
639
+ const current = Number(this.store.get(key)) || 0;
640
+ const newValue = current - decrement;
641
+ this.store.set(key, newValue.toString());
642
+ return newValue;
643
+ }
644
+ /**
645
+ * Sets a field in a hash.
646
+ * If the field already exists, its value is updated.
647
+ *
648
+ * @param key - The hash key.
649
+ * @param field - The field name.
650
+ * @param value - The value to store.
651
+ * @returns Resolves to `1` if a new field was added, `0` if an existing field was updated.
652
+ */
653
+ async hSet(key, field, value) {
654
+ const existingHash = JSON.parse(this.store.get(key) ?? "{}");
655
+ const isNewField = !Object.prototype.hasOwnProperty.call(
656
+ existingHash,
657
+ field
658
+ );
659
+ existingHash[field] = value;
660
+ this.store.set(key, JSON.stringify(existingHash));
661
+ return isNewField ? 1 : 0;
662
+ }
663
+ /**
664
+ * Retrieves a field from a hash.
665
+ *
666
+ * @param key - The hash key.
667
+ * @param field - The field name to retrieve.
668
+ * @returns Resolves to the field value, or `undefined` if the field does not exist.
669
+ */
670
+ async hGet(key, field) {
671
+ const hash = JSON.parse(this.store.get(key) ?? "{}");
672
+ return hash[field] ?? void 0;
673
+ }
674
+ /**
675
+ * Pushes elements to the left (head) of a list.
676
+ *
677
+ * @param key - The list key.
678
+ * @param values - One or more values to add.
679
+ * @returns Resolves to the length of the list after the operation.
680
+ */
681
+ async lPush(key, values) {
682
+ const list = JSON.parse(this.store.get(key) ?? "[]");
683
+ const newValues = Array.isArray(values) ? values : [values];
684
+ const updatedList = [...newValues.reverse(), ...list];
685
+ this.store.set(key, JSON.stringify(updatedList));
686
+ return updatedList.length;
687
+ }
688
+ /**
689
+ * Pushes elements to the right (tail) of a list.
690
+ *
691
+ * @param key - The list key.
692
+ * @param values - One or more values to add.
693
+ * @returns Resolves to the length of the list after the operation.
694
+ */
695
+ async rPush(key, values) {
696
+ const list = JSON.parse(this.store.get(key) ?? "[]");
697
+ const newValues = Array.isArray(values) ? values : [values];
698
+ const updatedList = [...list, ...newValues];
699
+ this.store.set(key, JSON.stringify(updatedList));
700
+ return updatedList.length;
701
+ }
702
+ /**
703
+ * Removes and returns the first element from a list.
704
+ *
705
+ * @param key - The list key.
706
+ * @returns Resolves to the removed element, or `null` if the list is empty.
707
+ */
708
+ async lPop(key) {
709
+ const list = JSON.parse(this.store.get(key) ?? "[]");
710
+ if (list.length === 0) return null;
711
+ const value = list.shift();
712
+ if (list.length > 0) {
713
+ this.store.set(key, JSON.stringify(list));
714
+ } else {
715
+ this.store.delete(key);
716
+ }
717
+ return value;
718
+ }
719
+ /**
720
+ * Removes and returns the last element from a list.
721
+ *
722
+ * @param key - The list key.
723
+ * @returns Resolves to the removed element, or `null` if the list is empty.
724
+ */
725
+ async rPop(key) {
726
+ const list = JSON.parse(this.store.get(key) ?? "[]");
727
+ if (list.length === 0) return null;
728
+ const value = list.pop();
729
+ if (list.length > 0) {
730
+ this.store.set(key, JSON.stringify(list));
731
+ } else {
732
+ this.store.delete(key);
733
+ }
734
+ return value;
735
+ }
736
+ /**
737
+ * Retrieves a range of elements from a list.
738
+ *
739
+ * @param key - The list key.
740
+ * @param start - The starting index.
741
+ * @param stop - The stopping index.
742
+ * @returns Resolves to an array containing the requested range.
743
+ */
744
+ async lRange(key, start, stop) {
745
+ const list = JSON.parse(this.store.get(key) ?? "[]");
746
+ const normalizedStop = stop === -1 ? list.length : stop + 1;
747
+ return list.slice(start, normalizedStop);
748
+ }
749
+ /**
750
+ * Adds elements to a set.
751
+ *
752
+ * @param key - The set key.
753
+ * @param values - One or more values to add.
754
+ * @returns Resolves to the number of new elements added.
755
+ */
756
+ async sAdd(key, values) {
757
+ const set = new Set(JSON.parse(this.store.get(key) ?? "[]"));
758
+ const newValues = Array.isArray(values) ? values : [values];
759
+ const initialSize = set.size;
760
+ for (const value of newValues) {
761
+ set.add(value);
762
+ }
763
+ this.store.set(key, JSON.stringify([...set]));
764
+ return set.size - initialSize;
765
+ }
766
+ /**
767
+ * Removes elements from a set.
768
+ *
769
+ * @param key - The set key.
770
+ * @param values - One or more values to remove.
771
+ * @returns Resolves to the number of elements removed.
772
+ */
773
+ async sRem(key, values) {
774
+ const set = new Set(JSON.parse(this.store.get(key) ?? "[]"));
775
+ const valuesToRemove = Array.isArray(values) ? values : [values];
776
+ const initialSize = set.size;
777
+ for (const value of valuesToRemove) {
778
+ set.delete(value);
779
+ }
780
+ this.store.set(key, JSON.stringify([...set]));
781
+ return initialSize - set.size;
782
+ }
783
+ /**
784
+ * Retrieves all elements from a set.
785
+ *
786
+ * @param key - The set key.
787
+ * @returns Resolves to an array of all set members.
788
+ */
789
+ async sMembers(key) {
790
+ return JSON.parse(this.store.get(key) ?? "[]");
791
+ }
792
+ /**
793
+ * Adds members to a sorted set with scores.
794
+ *
795
+ * @param key - The sorted set key.
796
+ * @param members - An array of objects containing `{ score, value }`.
797
+ * @returns Resolves to the number of new elements added.
798
+ */
799
+ async zAdd(key, members) {
800
+ const sortedSet = JSON.parse(
801
+ this.store.get(key) ?? "[]"
802
+ );
803
+ const initialSize = sortedSet.length;
804
+ for (const { score, value } of members) {
805
+ const existingIndex = sortedSet.findIndex(
806
+ (entry) => entry.value === value
807
+ );
808
+ if (existingIndex !== -1) {
809
+ sortedSet[existingIndex].score = score;
810
+ } else {
811
+ sortedSet.push({ score, value });
812
+ }
813
+ }
814
+ sortedSet.sort((a, b) => a.score - b.score);
815
+ this.store.set(key, JSON.stringify(sortedSet));
816
+ return sortedSet.length - initialSize;
817
+ }
818
+ /**
819
+ * Retrieves a range of elements from a sorted set.
820
+ *
821
+ * @param key - The sorted set key.
822
+ * @param start - The starting index.
823
+ * @param stop - The stopping index.
824
+ * @returns Resolves to an array of sorted set values in the range.
825
+ */
826
+ async zRange(key, start, stop) {
827
+ const sortedSet = JSON.parse(
828
+ this.store.get(key) ?? "[]"
829
+ );
830
+ const normalizedStop = stop === -1 ? sortedSet.length : stop + 1;
831
+ return sortedSet.slice(start, normalizedStop).map((entry) => entry.value);
832
+ }
833
+ /**
834
+ * Removes elements from a sorted set.
835
+ *
836
+ * @param key - The sorted set key.
837
+ * @param members - One or more values to remove.
838
+ * @returns Resolves to the number of elements removed.
839
+ */
840
+ async zRem(key, members) {
841
+ const sortedSet = JSON.parse(
842
+ this.store.get(key) ?? "[]"
843
+ );
844
+ const valuesToRemove = Array.isArray(members) ? members : [members];
845
+ const initialSize = sortedSet.length;
846
+ this.store.set(
847
+ key,
848
+ JSON.stringify(
849
+ sortedSet.filter((entry) => !valuesToRemove.includes(entry.value))
850
+ )
851
+ );
852
+ return initialSize - JSON.parse(this.store.get(key) ?? "[]").length;
853
+ }
538
854
  /**
539
855
  * Removes all keys from the store and clears all active expirations.
540
856
  *
@@ -549,6 +865,15 @@ var InMemoryPersistor = class {
549
865
  this.expiryTimestamps.clear();
550
866
  return "OK";
551
867
  }
868
+ /**
869
+ * Creates a new multi-command batch instance.
870
+ * Commands queued in this batch will be executed together when `exec()` is called.
871
+ *
872
+ * @returns A new `IPersistorMulti` instance for batching commands.
873
+ */
874
+ multi() {
875
+ return new InMemoryMulti(this);
876
+ }
552
877
  /**
553
878
  * Sets an expiration timeout for a key.
554
879
  * Cancels any existing expiration before setting a new one.
@@ -582,6 +907,329 @@ var InMemoryPersistor = class {
582
907
  }
583
908
  }
584
909
  };
910
+ var InMemoryMulti = class {
911
+ persistor;
912
+ commands = /* @__PURE__ */ new Set();
913
+ constructor(persistor) {
914
+ this.persistor = persistor;
915
+ }
916
+ /**
917
+ * Queues a `SET` command to store a key-value pair with optional expiration settings.
918
+ * The command will be executed when `exec()` is called.
919
+ *
920
+ * @param key - The storage key.
921
+ * @param value - The string value to store.
922
+ * @param options - Optional expiration settings.
923
+ * @returns The `IPersistorMulti` instance to allow method chaining.
924
+ */
925
+ set(key, value, options) {
926
+ this.commands.add(() => this.persistor.set(key, value, options));
927
+ return this;
928
+ }
929
+ /**
930
+ * Queues a `SETEX` command to store a key-value pair with an expiration time in seconds.
931
+ * The command will be executed when `exec()` is called.
932
+ *
933
+ * @param key - The storage key.
934
+ * @param seconds - Expiration time in seconds.
935
+ * @param value - The string value to store.
936
+ * @returns The `IPersistorMulti` instance to allow method chaining.
937
+ */
938
+ setEx(key, seconds2, value) {
939
+ this.commands.add(() => this.persistor.setEx(key, seconds2, value));
940
+ return this;
941
+ }
942
+ /**
943
+ * Queues a `PSETEX` command to store a key-value pair with an expiration time in milliseconds.
944
+ * The command will be executed when `exec()` is called.
945
+ *
946
+ * @param key - The storage key.
947
+ * @param milliseconds - Expiration time in milliseconds.
948
+ * @param value - The string value to store.
949
+ * @returns The `IPersistorMulti` instance to allow method chaining.
950
+ */
951
+ pSetEx(key, milliseconds, value) {
952
+ this.commands.add(() => this.persistor.pSetEx(key, milliseconds, value));
953
+ return this;
954
+ }
955
+ /**
956
+ * Queues a `SETNX` command to store a key-value pair **only if the key does not already exist**.
957
+ * The command will be executed when `exec()` is called.
958
+ *
959
+ * @param key - The storage key.
960
+ * @param value - The string value to store.
961
+ * @returns The `IPersistorMulti` instance to allow method chaining.
962
+ */
963
+ setNX(key, value) {
964
+ this.commands.add(() => this.persistor.setNX(key, value));
965
+ return this;
966
+ }
967
+ /**
968
+ * Queues a `GET` command to retrieve the value associated with a key.
969
+ * The command will be executed when `exec()` is called.
970
+ *
971
+ * @param key - The storage key to retrieve.
972
+ * @returns The `IPersistorMulti` instance to allow method chaining.
973
+ */
974
+ get(key) {
975
+ this.commands.add(() => this.persistor.get(key));
976
+ return this;
977
+ }
978
+ /**
979
+ * Queues a `DEL` command to delete a key from the store.
980
+ * The command will be executed when `exec()` is called.
981
+ *
982
+ * @param key - The storage key to delete.
983
+ * @returns The `IPersistorMulti` instance to allow method chaining.
984
+ */
985
+ del(key) {
986
+ this.commands.add(() => this.persistor.del(key));
987
+ return this;
988
+ }
989
+ /**
990
+ * Queues an `EXPIRE` command to set a time-to-live (TTL) in seconds for a key.
991
+ * The command will be executed when `exec()` is called.
992
+ *
993
+ * @param key - The storage key.
994
+ * @param seconds - TTL in seconds.
995
+ * @returns The `IPersistorMulti` instance to allow method chaining.
996
+ */
997
+ expire(key, seconds2) {
998
+ this.commands.add(() => this.persistor.expire(key, seconds2));
999
+ return this;
1000
+ }
1001
+ /**
1002
+ * Queues a `TTL` command to get the remaining time-to-live (TTL) of a key in seconds.
1003
+ * The command will be executed when `exec()` is called.
1004
+ *
1005
+ * @param key - The storage key to check.
1006
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1007
+ */
1008
+ ttl(key) {
1009
+ this.commands.add(() => this.persistor.ttl(key));
1010
+ return this;
1011
+ }
1012
+ /**
1013
+ * Queues an `exists` operation in the batch.
1014
+ * @param key - The key(s) to check existence.
1015
+ * @returns The multi instance for method chaining.
1016
+ */
1017
+ exists(key) {
1018
+ this.commands.add(() => this.persistor.exists(key));
1019
+ return this;
1020
+ }
1021
+ /**
1022
+ * Queues an `incr` operation in the batch.
1023
+ * @param key - The key to increment.
1024
+ * @returns The multi instance for method chaining.
1025
+ */
1026
+ incr(key) {
1027
+ this.commands.add(() => this.persistor.incr(key));
1028
+ return this;
1029
+ }
1030
+ /**
1031
+ * Queues an `incrBy` operation in the batch.
1032
+ * @param key - The key to increment.
1033
+ * @param increment - The amount to increment by.
1034
+ * @returns The multi instance for method chaining.
1035
+ */
1036
+ incrBy(key, increment) {
1037
+ this.commands.add(() => this.persistor.incrBy(key, increment));
1038
+ return this;
1039
+ }
1040
+ /**
1041
+ * Queues a `decr` operation in the batch.
1042
+ * @param key - The key to decrement.
1043
+ * @returns The multi instance for method chaining.
1044
+ */
1045
+ decr(key) {
1046
+ this.commands.add(() => this.persistor.decr(key));
1047
+ return this;
1048
+ }
1049
+ /**
1050
+ * Queues a `decrBy` operation in the batch.
1051
+ * @param key - The key to decrement.
1052
+ * @param decrement - The amount to decrement by.
1053
+ * @returns The multi instance for method chaining.
1054
+ */
1055
+ decrBy(key, decrement) {
1056
+ this.commands.add(() => this.persistor.decrBy(key, decrement));
1057
+ return this;
1058
+ }
1059
+ /**
1060
+ * Queues a `flushAll` operation in the batch.
1061
+ * @returns The multi instance for method chaining.
1062
+ */
1063
+ flushAll() {
1064
+ this.commands.add(() => this.persistor.flushAll());
1065
+ return this;
1066
+ }
1067
+ /**
1068
+ * Queues an `hSet` command to store a field-value pair in a hash.
1069
+ * The command will be executed when `exec()` is called.
1070
+ *
1071
+ * @param key - The hash key.
1072
+ * @param field - The field name.
1073
+ * @param value - The value to store.
1074
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1075
+ */
1076
+ hSet(key, field, value) {
1077
+ this.commands.add(() => this.persistor.hSet(key, field, value));
1078
+ return this;
1079
+ }
1080
+ /**
1081
+ * Queues an `hGet` command to retrieve a field value from a hash.
1082
+ * The command will be executed when `exec()` is called.
1083
+ *
1084
+ * @param key - The hash key.
1085
+ * @param field - The field to retrieve.
1086
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1087
+ */
1088
+ hGet(key, field) {
1089
+ this.commands.add(() => this.persistor.hGet(key, field));
1090
+ return this;
1091
+ }
1092
+ /**
1093
+ * Queues an `lPush` command to add elements to the left (head) of a list.
1094
+ * The command will be executed when `exec()` is called.
1095
+ *
1096
+ * @param key - The list key.
1097
+ * @param values - The values to add.
1098
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1099
+ */
1100
+ lPush(key, values) {
1101
+ this.commands.add(() => this.persistor.lPush(key, values));
1102
+ return this;
1103
+ }
1104
+ /**
1105
+ * Queues an `rPush` command to add elements to the right (tail) of a list.
1106
+ * The command will be executed when `exec()` is called.
1107
+ *
1108
+ * @param key - The list key.
1109
+ * @param values - The values to add.
1110
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1111
+ */
1112
+ rPush(key, values) {
1113
+ this.commands.add(() => this.persistor.rPush(key, values));
1114
+ return this;
1115
+ }
1116
+ /**
1117
+ * Queues an `lPop` command to remove and return the first element of a list.
1118
+ * The command will be executed when `exec()` is called.
1119
+ *
1120
+ * @param key - The list key.
1121
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1122
+ */
1123
+ lPop(key) {
1124
+ this.commands.add(() => this.persistor.lPop(key));
1125
+ return this;
1126
+ }
1127
+ /**
1128
+ * Queues an `rPop` command to remove and return the last element of a list.
1129
+ * The command will be executed when `exec()` is called.
1130
+ *
1131
+ * @param key - The list key.
1132
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1133
+ */
1134
+ rPop(key) {
1135
+ this.commands.add(() => this.persistor.rPop(key));
1136
+ return this;
1137
+ }
1138
+ /**
1139
+ * Queues an `lRange` command to retrieve a range of elements from a list.
1140
+ * The command will be executed when `exec()` is called.
1141
+ *
1142
+ * @param key - The list key.
1143
+ * @param start - The start index.
1144
+ * @param stop - The stop index (inclusive).
1145
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1146
+ */
1147
+ lRange(key, start, stop) {
1148
+ this.commands.add(() => this.persistor.lRange(key, start, stop));
1149
+ return this;
1150
+ }
1151
+ /**
1152
+ * Queues an `sAdd` command to add elements to a set.
1153
+ * The command will be executed when `exec()` is called.
1154
+ *
1155
+ * @param key - The set key.
1156
+ * @param values - The values to add.
1157
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1158
+ */
1159
+ sAdd(key, values) {
1160
+ this.commands.add(() => this.persistor.sAdd(key, values));
1161
+ return this;
1162
+ }
1163
+ /**
1164
+ * Queues an `sRem` command to remove elements from a set.
1165
+ * The command will be executed when `exec()` is called.
1166
+ *
1167
+ * @param key - The set key.
1168
+ * @param values - The values to remove.
1169
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1170
+ */
1171
+ sRem(key, values) {
1172
+ this.commands.add(() => this.persistor.sRem(key, values));
1173
+ return this;
1174
+ }
1175
+ /**
1176
+ * Queues an `sMembers` command to retrieve all members of a set.
1177
+ * The command will be executed when `exec()` is called.
1178
+ *
1179
+ * @param key - The set key.
1180
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1181
+ */
1182
+ sMembers(key) {
1183
+ this.commands.add(() => this.persistor.sMembers(key));
1184
+ return this;
1185
+ }
1186
+ /**
1187
+ * Queues a `zAdd` command to add elements to a sorted set with scores.
1188
+ * The command will be executed when `exec()` is called.
1189
+ *
1190
+ * @param key - The sorted set key.
1191
+ * @param members - An array of objects with `score` and `value`.
1192
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1193
+ */
1194
+ zAdd(key, members) {
1195
+ this.commands.add(() => this.persistor.zAdd(key, members));
1196
+ return this;
1197
+ }
1198
+ /**
1199
+ * Queues a `zRange` command to retrieve a range of elements from a sorted set.
1200
+ * The command will be executed when `exec()` is called.
1201
+ *
1202
+ * @param key - The sorted set key.
1203
+ * @param start - The start index.
1204
+ * @param stop - The stop index (inclusive).
1205
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1206
+ */
1207
+ zRange(key, start, stop) {
1208
+ this.commands.add(() => this.persistor.zRange(key, start, stop));
1209
+ return this;
1210
+ }
1211
+ /**
1212
+ * Queues a `zRem` command to remove elements from a sorted set.
1213
+ * The command will be executed when `exec()` is called.
1214
+ *
1215
+ * @param key - The sorted set key.
1216
+ * @param members - The members to remove.
1217
+ * @returns The `IPersistorMulti` instance to allow method chaining.
1218
+ */
1219
+ zRem(key, members) {
1220
+ this.commands.add(() => this.persistor.zRem(key, members));
1221
+ return this;
1222
+ }
1223
+ /**
1224
+ * Executes multiple commands in a batch operation.
1225
+ * Each command is executed in sequence, and results are collected in an array.
1226
+ *
1227
+ * @returns Resolves to an array containing the results of each queued command.
1228
+ */
1229
+ async exec() {
1230
+ return Promise.all([...this.commands].map((cmd) => cmd()));
1231
+ }
1232
+ };
585
1233
 
586
1234
  // src/time.ts
587
1235
  var time_exports = {};