@baeta/cache-ioredis 2.0.0-next.16 → 2.0.0-next.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @baeta/cache-ioredis
2
2
 
3
+ ## 2.0.0-next.17
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`37364b1`](https://github.com/andreisergiu98/baeta/commit/37364b1eceac797cd4077e2e26fb1492c752bf6c), [`7cd558c`](https://github.com/andreisergiu98/baeta/commit/7cd558c2a2c1111df0b6de663b6db50ad881bc88)]:
8
+ - @baeta/cache@2.0.0-next.17
9
+
3
10
  ## 2.0.0-next.16
4
11
 
5
12
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { CacheClient, CacheClientArgs, CacheClientOptions, CacheClientSaveOptions, ItemCacheKey, QueryCacheIndexKey, QueryCacheKey } from "@baeta/cache";
2
2
  import { RedisScripts } from "@baeta/cache-redis-common";
3
3
  import Redis, { Cluster } from "ioredis";
4
-
5
4
  //#region lib/cache-client.d.ts
6
5
  interface RedisCacheClientOptions extends CacheClientOptions {
7
6
  /**
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { assertNoPipelineErrors, batchPipeline, createRedisScripts } from "@baet
3
3
  import { doBatched } from "@baeta/cache/sdk";
4
4
  //#region lib/cache-client.ts
5
5
  const INDEX_BUFFER_MS = 1e3;
6
- const MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024;
6
+ const MAX_PIPELINE_SIZE_LIMIT = 52428800;
7
7
  const MAX_PIPELINE_COMMAND_LIMIT = 1e5;
8
8
  const MAX_COMMAND_KEYS_LIMIT = 1e5;
9
9
  var RedisCacheClient = class extends CacheClient {
@@ -42,6 +42,10 @@ var RedisCacheClient = class extends CacheClient {
42
42
  async saveItems(items, options, saveOptions = {}) {
43
43
  if (items.length === 0) return;
44
44
  const expiresAt = Date.now() + options.ttlMs;
45
+ const serialized = items.map(([key, value]) => ({
46
+ key,
47
+ value: options.serialize(value)
48
+ }));
45
49
  await batchPipeline({
46
50
  makePipeline: () => this.redis.pipeline(),
47
51
  addCommand: (pipeline, item) => {
@@ -49,16 +53,14 @@ var RedisCacheClient = class extends CacheClient {
49
53
  else pipeline.set(item.key, item.value, "PXAT", expiresAt, "NX");
50
54
  },
51
55
  executePipeline: async (pipeline) => {
52
- assertNoPipelineErrors(await pipeline.exec());
56
+ const result = await pipeline.exec();
57
+ assertNoPipelineErrors(result);
53
58
  return [];
54
59
  },
55
60
  estimateSize: (item) => {
56
61
  return item.key.length + item.value.length;
57
62
  },
58
- items: items.map(([key, value]) => ({
59
- key,
60
- value: options.serialize(value)
61
- })),
63
+ items: serialized,
62
64
  maxBatchBytes: this.maxPipelineSizeLimit,
63
65
  maxBatchCount: this.maxPipelineCommandLimit
64
66
  });
@@ -116,7 +118,8 @@ var RedisCacheClient = class extends CacheClient {
116
118
  tx.zremrangebyscore(indexKey, "-inf", now - INDEX_BUFFER_MS);
117
119
  tx.pexpireat(indexKey, expiresAt + INDEX_BUFFER_MS);
118
120
  }
119
- assertNoPipelineErrors(await tx.exec());
121
+ const result = await tx.exec();
122
+ assertNoPipelineErrors(result);
120
123
  }
121
124
  async deleteQueries(indexes) {
122
125
  if (indexes.length === 0) return;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../lib/cache-client.ts"],"sourcesContent":["import {\n\tCacheClient,\n\ttype CacheClientSaveOptions,\n\ttype ItemCacheKey,\n\ttype QueryCacheIndexKey,\n\ttype QueryCacheKey,\n\ttype CacheClientArgs,\n\ttype CacheClientOptions,\n} from '@baeta/cache';\nimport {\n\tassertNoPipelineErrors,\n\tbatchPipeline,\n\tcreateRedisScripts,\n\ttype RedisScripts,\n} from '@baeta/cache-redis-common';\nimport { doBatched } from '@baeta/cache/sdk';\nimport type Redis from 'ioredis';\nimport type { Cluster as RedisCluster } from 'ioredis';\n\nconst INDEX_BUFFER_MS = 1_000;\nconst MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024; // 50MB\nconst MAX_PIPELINE_COMMAND_LIMIT = 100_000;\nconst MAX_COMMAND_KEYS_LIMIT = 100_000;\n\nexport interface RedisCacheClientOptions extends CacheClientOptions {\n\t/**\n\t * Maximum total size of commands in a single pipeline batch. If the batch exceeds this size, it will be executed immediately.\n\t * @defaultValue 50 * 1024 * 1024 (50MB)\n\t */\n\tmaxPipelineSizeLimit?: number;\n\t/**\n\t * Maximum number of commands in a single pipeline batch. If the batch exceeds this number, it will be executed immediately.\n\t * @defaultValue 100_000\n\t */\n\tmaxPipelineCommandLimit?: number;\n\t/**\n\t * Maximum number of keys in a single command. If the number of keys exceeds this limit, multiple commands will be executed.\n\t * @defaultValue 100_000\n\t */\n\tmaxCommandKeysLimit?: number;\n}\n\nexport class RedisCacheClient extends CacheClient {\n\tredis: Redis | RedisCluster;\n\tprotected maxPipelineSizeLimit: number;\n\tprotected maxPipelineCommandLimit: number;\n\tprotected maxCommandKeysLimit: number;\n\tprotected scripts: RedisScripts;\n\n\tconstructor(redis: Redis | RedisCluster, options?: RedisCacheClientOptions) {\n\t\tsuper({\n\t\t\tnamespace: options?.namespace,\n\t\t\trevision: options?.revision,\n\t\t\tttlMs: options?.ttlMs,\n\t\t});\n\t\tthis.redis = redis;\n\t\tthis.maxPipelineSizeLimit = options?.maxPipelineSizeLimit ?? MAX_PIPELINE_SIZE_LIMIT;\n\t\tthis.maxPipelineCommandLimit = options?.maxPipelineCommandLimit ?? MAX_PIPELINE_COMMAND_LIMIT;\n\t\tthis.maxCommandKeysLimit = options?.maxCommandKeysLimit ?? MAX_COMMAND_KEYS_LIMIT;\n\t\tconst loadScript = async (script: string) => {\n\t\t\treturn await this.redis.script('LOAD', script);\n\t\t};\n\t\tconst evalSha = async (sha: string, keys: string[], args: string[]) => {\n\t\t\treturn await this.redis.evalsha(sha, keys.length, ...keys, ...args);\n\t\t};\n\t\tthis.scripts = createRedisScripts(loadScript, evalSha);\n\t}\n\n\tasync getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst values: Array<Item | null> = [];\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tconst batchValues = await this.redis.mget(batch);\n\t\t\tfor (const value of batchValues) {\n\t\t\t\tvalues.push(value == null ? null : options.parse(value));\n\t\t\t}\n\t\t});\n\t\treturn values;\n\t}\n\n\tasync saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions: CacheClientSaveOptions = {},\n\t): Promise<void> {\n\t\tif (items.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst serialized = items.map(([key, value]) => ({\n\t\t\tkey,\n\t\t\tvalue: options.serialize(value),\n\t\t}));\n\t\tawait batchPipeline({\n\t\t\tmakePipeline: () => this.redis.pipeline(),\n\t\t\taddCommand: (pipeline, item) => {\n\t\t\t\tif (saveOptions.disableOverwrite !== true) {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt);\n\t\t\t\t} else {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt, 'NX');\n\t\t\t\t}\n\t\t\t},\n\t\t\texecutePipeline: async (pipeline) => {\n\t\t\t\tconst result = await pipeline.exec();\n\t\t\t\tassertNoPipelineErrors(result);\n\t\t\t\treturn [];\n\t\t\t},\n\t\t\testimateSize: (item) => {\n\t\t\t\treturn item.key.length + item.value.length;\n\t\t\t},\n\t\t\titems: serialized,\n\t\t\tmaxBatchBytes: this.maxPipelineSizeLimit,\n\t\t\tmaxBatchCount: this.maxPipelineCommandLimit,\n\t\t});\n\t}\n\n\tasync saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (items.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst tx = this.redis.multi();\n\t\tfor (const item of items) {\n\t\t\ttx.get(item[0]);\n\t\t\ttx.set(item[0], options.serialize(item[1]), 'PXAT', expiresAt);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t\tconst results: Array<Item | null> = [];\n\t\tfor (let i = 0; i < result.length; i += 2) {\n\t\t\tconst value = result[i][1];\n\t\t\tresults.push(value == null ? null : options.parse(value as string));\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync deleteItems(keys: ItemCacheKey[]): Promise<void> {\n\t\tif (keys.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tawait this.redis.unlink(batch);\n\t\t});\n\t}\n\n\tasync deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst tx = this.redis.multi();\n\t\tfor (const key of keys) {\n\t\t\ttx.get(key);\n\t\t\ttx.unlink(key);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t\tconst results: Array<Item | null> = [];\n\t\tfor (let i = 0; i < result.length; i += 2) {\n\t\t\tconst value = result[i][1];\n\t\t\tresults.push(value == null ? null : options.parse(value as string));\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null> {\n\t\tconst meta = await this.redis.get(key);\n\t\treturn meta == null ? null : options.parse(meta);\n\t}\n\n\tasync saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void> {\n\t\tconst now = Date.now();\n\t\tconst expiresAt = now + options.ttlMs;\n\t\tconst tx = this.redis.multi();\n\t\ttx.set(key, options.serialize(metadata), 'PXAT', expiresAt);\n\t\tfor (const indexKey of indexes) {\n\t\t\ttx.zadd(indexKey, expiresAt, key);\n\t\t\ttx.zremrangebyscore(indexKey, '-inf', now - INDEX_BUFFER_MS);\n\t\t\ttx.pexpireat(indexKey, expiresAt + INDEX_BUFFER_MS);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t}\n\n\tasync deleteQueries(indexes: QueryCacheIndexKey[]): Promise<void> {\n\t\tif (indexes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = await this.scripts.deleteQueriesScript(indexes, []);\n\t\tif (typeof result !== 'number') {\n\t\t\tthrow new Error(`Unexpected non-number result from Redis script: ${typeof result}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAmBA,MAAM,kBAAkB;AACxB,MAAM,0BAA0B,KAAK,OAAO;AAC5C,MAAM,6BAA6B;AACnC,MAAM,yBAAyB;AAoB/B,IAAa,mBAAb,cAAsC,YAAY;CACjD;CACA;CACA;CACA;CACA;CAEA,YAAY,OAA6B,SAAmC;EAC3E,MAAM;GACL,WAAW,SAAS;GACpB,UAAU,SAAS;GACnB,OAAO,SAAS;EACjB,CAAC;EACD,KAAK,QAAQ;EACb,KAAK,uBAAuB,SAAS,wBAAwB;EAC7D,KAAK,0BAA0B,SAAS,2BAA2B;EACnE,KAAK,sBAAsB,SAAS,uBAAuB;EAC3D,MAAM,aAAa,OAAO,WAAmB;GAC5C,OAAO,MAAM,KAAK,MAAM,OAAO,QAAQ,MAAM;EAC9C;EACA,MAAM,UAAU,OAAO,KAAa,MAAgB,SAAmB;GACtE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rB,MAAM,YAAY,MAAM,QAAQ;EAChC,MAAM,KAAK,KAAK,MAAM,MAAM;EAC5B,GAAG,IAAI,KAAK,QAAQ,UAAU,QAAQ,GAAG,QAAQ,SAAS;EAC1D,KAAK,MAAM,YAAY,SAAS;GAC/B,GAAG,KAAK,UAAU,WAAW,GAAG;GAChC,GAAG,iBAAiB,UAAU,QAAQ,MAAM,eAAe;GAC3D,GAAG,UAAU,UAAU,YAAY,eAAe;EACnD;EAEA,uBAAuB,MADF,GAAG,KAAK,CACA;CAC9B;CAEA,MAAM,cAAc,SAA8C;EACjE,IAAI,QAAQ,WAAW,GACtB;EAED,MAAM,SAAS,MAAM,KAAK,QAAQ,oBAAoB,SAAS,CAAC,CAAC;EACjE,IAAI,OAAO,WAAW,UACrB,MAAM,IAAI,MAAM,mDAAmD,OAAO,QAAQ;CAEpF;AACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/cache-client.ts"],"sourcesContent":["import {\n\tCacheClient,\n\ttype CacheClientSaveOptions,\n\ttype ItemCacheKey,\n\ttype QueryCacheIndexKey,\n\ttype QueryCacheKey,\n\ttype CacheClientArgs,\n\ttype CacheClientOptions,\n} from '@baeta/cache';\nimport {\n\tassertNoPipelineErrors,\n\tbatchPipeline,\n\tcreateRedisScripts,\n\ttype RedisScripts,\n} from '@baeta/cache-redis-common';\nimport { doBatched } from '@baeta/cache/sdk';\nimport type Redis from 'ioredis';\nimport type { Cluster as RedisCluster } from 'ioredis';\n\nconst INDEX_BUFFER_MS = 1_000;\nconst MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024; // 50MB\nconst MAX_PIPELINE_COMMAND_LIMIT = 100_000;\nconst MAX_COMMAND_KEYS_LIMIT = 100_000;\n\nexport interface RedisCacheClientOptions extends CacheClientOptions {\n\t/**\n\t * Maximum total size of commands in a single pipeline batch. If the batch exceeds this size, it will be executed immediately.\n\t * @defaultValue 50 * 1024 * 1024 (50MB)\n\t */\n\tmaxPipelineSizeLimit?: number;\n\t/**\n\t * Maximum number of commands in a single pipeline batch. If the batch exceeds this number, it will be executed immediately.\n\t * @defaultValue 100_000\n\t */\n\tmaxPipelineCommandLimit?: number;\n\t/**\n\t * Maximum number of keys in a single command. If the number of keys exceeds this limit, multiple commands will be executed.\n\t * @defaultValue 100_000\n\t */\n\tmaxCommandKeysLimit?: number;\n}\n\nexport class RedisCacheClient extends CacheClient {\n\tredis: Redis | RedisCluster;\n\tprotected maxPipelineSizeLimit: number;\n\tprotected maxPipelineCommandLimit: number;\n\tprotected maxCommandKeysLimit: number;\n\tprotected scripts: RedisScripts;\n\n\tconstructor(redis: Redis | RedisCluster, options?: RedisCacheClientOptions) {\n\t\tsuper({\n\t\t\tnamespace: options?.namespace,\n\t\t\trevision: options?.revision,\n\t\t\tttlMs: options?.ttlMs,\n\t\t});\n\t\tthis.redis = redis;\n\t\tthis.maxPipelineSizeLimit = options?.maxPipelineSizeLimit ?? MAX_PIPELINE_SIZE_LIMIT;\n\t\tthis.maxPipelineCommandLimit = options?.maxPipelineCommandLimit ?? MAX_PIPELINE_COMMAND_LIMIT;\n\t\tthis.maxCommandKeysLimit = options?.maxCommandKeysLimit ?? MAX_COMMAND_KEYS_LIMIT;\n\t\tconst loadScript = async (script: string) => {\n\t\t\treturn await this.redis.script('LOAD', script);\n\t\t};\n\t\tconst evalSha = async (sha: string, keys: string[], args: string[]) => {\n\t\t\treturn await this.redis.evalsha(sha, keys.length, ...keys, ...args);\n\t\t};\n\t\tthis.scripts = createRedisScripts(loadScript, evalSha);\n\t}\n\n\tasync getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst values: Array<Item | null> = [];\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tconst batchValues = await this.redis.mget(batch);\n\t\t\tfor (const value of batchValues) {\n\t\t\t\tvalues.push(value == null ? null : options.parse(value));\n\t\t\t}\n\t\t});\n\t\treturn values;\n\t}\n\n\tasync saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions: CacheClientSaveOptions = {},\n\t): Promise<void> {\n\t\tif (items.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst serialized = items.map(([key, value]) => ({\n\t\t\tkey,\n\t\t\tvalue: options.serialize(value),\n\t\t}));\n\t\tawait batchPipeline({\n\t\t\tmakePipeline: () => this.redis.pipeline(),\n\t\t\taddCommand: (pipeline, item) => {\n\t\t\t\tif (saveOptions.disableOverwrite !== true) {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt);\n\t\t\t\t} else {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt, 'NX');\n\t\t\t\t}\n\t\t\t},\n\t\t\texecutePipeline: async (pipeline) => {\n\t\t\t\tconst result = await pipeline.exec();\n\t\t\t\tassertNoPipelineErrors(result);\n\t\t\t\treturn [];\n\t\t\t},\n\t\t\testimateSize: (item) => {\n\t\t\t\treturn item.key.length + item.value.length;\n\t\t\t},\n\t\t\titems: serialized,\n\t\t\tmaxBatchBytes: this.maxPipelineSizeLimit,\n\t\t\tmaxBatchCount: this.maxPipelineCommandLimit,\n\t\t});\n\t}\n\n\tasync saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (items.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst tx = this.redis.multi();\n\t\tfor (const item of items) {\n\t\t\ttx.get(item[0]);\n\t\t\ttx.set(item[0], options.serialize(item[1]), 'PXAT', expiresAt);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t\tconst results: Array<Item | null> = [];\n\t\tfor (let i = 0; i < result.length; i += 2) {\n\t\t\tconst value = result[i][1];\n\t\t\tresults.push(value == null ? null : options.parse(value as string));\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync deleteItems(keys: ItemCacheKey[]): Promise<void> {\n\t\tif (keys.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tawait this.redis.unlink(batch);\n\t\t});\n\t}\n\n\tasync deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst tx = this.redis.multi();\n\t\tfor (const key of keys) {\n\t\t\ttx.get(key);\n\t\t\ttx.unlink(key);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t\tconst results: Array<Item | null> = [];\n\t\tfor (let i = 0; i < result.length; i += 2) {\n\t\t\tconst value = result[i][1];\n\t\t\tresults.push(value == null ? null : options.parse(value as string));\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null> {\n\t\tconst meta = await this.redis.get(key);\n\t\treturn meta == null ? null : options.parse(meta);\n\t}\n\n\tasync saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void> {\n\t\tconst now = Date.now();\n\t\tconst expiresAt = now + options.ttlMs;\n\t\tconst tx = this.redis.multi();\n\t\ttx.set(key, options.serialize(metadata), 'PXAT', expiresAt);\n\t\tfor (const indexKey of indexes) {\n\t\t\ttx.zadd(indexKey, expiresAt, key);\n\t\t\ttx.zremrangebyscore(indexKey, '-inf', now - INDEX_BUFFER_MS);\n\t\t\ttx.pexpireat(indexKey, expiresAt + INDEX_BUFFER_MS);\n\t\t}\n\t\tconst result = await tx.exec();\n\t\tassertNoPipelineErrors(result);\n\t}\n\n\tasync deleteQueries(indexes: QueryCacheIndexKey[]): Promise<void> {\n\t\tif (indexes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = await this.scripts.deleteQueriesScript(indexes, []);\n\t\tif (typeof result !== 'number') {\n\t\t\tthrow new Error(`Unexpected non-number result from Redis script: ${typeof result}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAmBA,MAAM,kBAAkB;AACxB,MAAM,0BAA0B;AAChC,MAAM,6BAA6B;AACnC,MAAM,yBAAyB;AAoB/B,IAAa,mBAAb,cAAsC,YAAY;CACjD;CACA;CACA;CACA;CACA;CAEA,YAAY,OAA6B,SAAmC;EAC3E,MAAM;GACL,WAAW,SAAS;GACpB,UAAU,SAAS;GACnB,OAAO,SAAS;EACjB,CAAC;EACD,KAAK,QAAQ;EACb,KAAK,uBAAuB,SAAS,wBAAwB;EAC7D,KAAK,0BAA0B,SAAS,2BAA2B;EACnE,KAAK,sBAAsB,SAAS,uBAAuB;EAC3D,MAAM,aAAa,OAAO,WAAmB;GAC5C,OAAO,MAAM,KAAK,MAAM,OAAO,QAAQ,MAAM;EAC9C;EACA,MAAM,UAAU,OAAO,KAAa,MAAgB,SAAmB;GACtE,OAAO,MAAM,KAAK,MAAM,QAAQ,KAAK,KAAK,QAAQ,GAAG,MAAM,GAAG,IAAI;EACnE;EACA,KAAK,UAAU,mBAAmB,YAAY,OAAO;CACtD;CAEA,MAAM,gBACL,MACA,SAC8B;EAC9B,IAAI,KAAK,WAAW,GACnB,OAAO,CAAC;EAET,MAAM,SAA6B,CAAC;EACpC,MAAM,UAAU,MAAM,KAAK,qBAAqB,OAAO,UAAU;GAChE,MAAM,cAAc,MAAM,KAAK,MAAM,KAAK,KAAK;GAC/C,KAAK,MAAM,SAAS,aACn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K;EAC7B,uBAAuB,MAAM;CAC9B;CAEA,MAAM,cAAc,SAA8C;EACjE,IAAI,QAAQ,WAAW,GACtB;EAED,MAAM,SAAS,MAAM,KAAK,QAAQ,oBAAoB,SAAS,CAAC,CAAC;EACjE,IAAI,OAAO,WAAW,UACrB,MAAM,IAAI,MAAM,mDAAmD,OAAO,QAAQ;CAEpF;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/cache-ioredis",
3
- "version": "2.0.0-next.16",
3
+ "version": "2.0.0-next.17",
4
4
  "description": "ioredis cache adapter for Baeta.",
5
5
  "keywords": [
6
6
  "baeta",
@@ -59,16 +59,16 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@baeta/builder": "^0.0.0",
62
- "@baeta/cache": "^2.0.0-next.16",
62
+ "@baeta/cache": "^2.0.0-next.17",
63
63
  "@baeta/testing": "^0.0.0",
64
64
  "@baeta/tests-cache-clients": "^0.0.0",
65
65
  "@baeta/tsconfig": "^0.0.0",
66
- "ioredis": "^5.11.1",
66
+ "ioredis": "^6.0.0",
67
67
  "typescript": "^6.0.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@baeta/cache": "^2.0.0-next.16",
71
- "ioredis": "^5.10.0"
70
+ "@baeta/cache": "^2.0.0-next.17",
71
+ "ioredis": "^6.0.0"
72
72
  },
73
73
  "ava": {
74
74
  "extensions": [