@mastra/redis 1.4.11-alpha.0 → 1.4.12-alpha.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/cache.d.ts CHANGED
@@ -17,6 +17,15 @@ export interface RedisClient {
17
17
  }
18
18
  export interface RedisServerCacheOptions {
19
19
  keyPrefix?: string;
20
+ /**
21
+ * Lifetime of cached values in seconds, refreshed on every write. Defaults to
22
+ * 300. `0` means no expiry.
23
+ *
24
+ * A cache list and its index counter always share this TTL: if the counter
25
+ * outlived the list, index allocation would restart at 0 while subscribers
26
+ * still expect the previous numbering, and every new frame would be dropped
27
+ * as a duplicate.
28
+ */
20
29
  ttlSeconds?: number;
21
30
  /**
22
31
  * Run a Lua script with the given KEYS and ARGV. Defaults to the ioredis
@@ -31,11 +40,12 @@ export interface RedisServerCacheOptions {
31
40
  getListRange?: (client: RedisClient, key: string, start: number, stop: number) => Promise<unknown[]>;
32
41
  }
33
42
  /**
34
- * Atomic "allocate index + append + refresh TTLs" used by `listPushIndexed`.
43
+ * Atomic "allocate index + append + refresh TTL" used by `listPushIndexed`.
35
44
  *
36
45
  * KEYS[1] = list key, KEYS[2] = counter key
37
46
  * ARGV[1] = JSON-serialized object WITHOUT an `index` property
38
- * ARGV[2] = TTL in seconds (0 = no expiry)
47
+ * ARGV[2] = TTL in seconds (0 = no expiry), applied to BOTH keys
48
+
39
49
  *
40
50
  * The index is spliced into the JSON text as the first property rather than
41
51
  * decoded/re-encoded with cjson, which would silently alter large integers
@@ -71,10 +81,15 @@ export declare class RedisServerCache extends MastraServerCache {
71
81
  increment(key: string): Promise<number>;
72
82
  /**
73
83
  * Single round-trip index allocation + list append + TTL refresh via Lua.
74
- * This is the durable stream per-chunk hot path (issue #22477): the composed
75
- * default costs four awaited commands (INCR, EXPIRE, RPUSH, EXPIRE).
84
+ * This is the durable stream per-chunk hot path (issue #22477).
85
+ */
86
+ listPushIndexed(listKey: string, counterKey: string, value: Record<string, unknown>, ttlMs?: number): Promise<number>;
87
+ /**
88
+ * `INCR` then `RPUSH`, each followed by the same `EXPIRE` the script applies.
89
+ * Not atomic: concurrent writers can interleave, so a list position may not
90
+ * match its index (Redis Cluster atomicity is tracked in COR-1491).
76
91
  */
77
- listPushIndexed(listKey: string, counterKey: string, value: Record<string, unknown>): Promise<number>;
92
+ private composedPushIndexed;
78
93
  }
79
94
  export declare const upstashPreset: Pick<RedisServerCacheOptions, 'setWithExpiry' | 'scanKeys' | 'evalScript'>;
80
95
  export declare const nodeRedisPreset: Pick<RedisServerCacheOptions, 'setWithExpiry' | 'scanKeys' | 'getListLength' | 'pushToList' | 'getListRange' | 'evalScript'>;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACrE,GAAG,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,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AE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUpE;IAEK,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7C;IAEK,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzD;IAEK,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAE,MAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAI/E;IAEK,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvC;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAa3B;IAEK,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAS5C;IAED;;;OAGG;IACG,eAAe,CACnB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CA+BjB;IAED;;;;OAIG;YACW,mBAAmB;CAelC;AAED,eAAO,MAAM,aAAa,EAAE,IAAI,CAAC,uBAAuB,EAAE,eAAe,GAAG,UAAU,GAAG,YAAY,CAKpG,CAAC;AASF,eAAO,MAAM,eAAe,EAAE,IAAI,CAChC,uBAAuB,EACvB,eAAe,GAAG,UAAU,GAAG,eAAe,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,CAS9F,CAAC"}
@@ -3,7 +3,7 @@ name: mastra-redis
3
3
  description: Documentation for @mastra/redis. Use when working with @mastra/redis APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/redis"
6
- version: "1.4.11-alpha.0"
6
+ version: "1.4.12-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.11-alpha.0",
2
+ "version": "1.4.12-alpha.0",
3
3
  "package": "@mastra/redis",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -165,7 +165,7 @@ export const redisAgent = new Agent({
165
165
  name: 'Redis Agent',
166
166
  instructions:
167
167
  'You are an AI agent with the ability to automatically recall memories from previous interactions.',
168
- model: 'openai/gpt-5.6-sol',
168
+ model: 'openai/gpt-6.1-sol',
169
169
  memory: new Memory({
170
170
  storage: new RedisStore({
171
171
  id: 'redis-agent-storage',
package/dist/index.cjs CHANGED
@@ -139,7 +139,7 @@ var RedisDB = class {
139
139
  * generation comes from the clock, so it still outranks every fence the expired
140
140
  * record issued, and a write checked against a missing record is rejected.
141
141
  */
142
- const RUN_CLAIM_RETENTION_MS = 10080 * 60 * 1e3;
142
+ const RUN_CLAIM_RETENTION_MS = 6048e5;
143
143
  function runClaimKey(claims, runId) {
144
144
  return `${claims}:run_id:${runId}`;
145
145
  }
@@ -1362,12 +1362,13 @@ var ScoresRedis = class extends _mastra_core_storage.ScoresStorage {
1362
1362
  }
1363
1363
  const now = /* @__PURE__ */ new Date();
1364
1364
  const id = crypto.randomUUID();
1365
- const { key, processedRecord } = processRecord(_mastra_core_storage.TABLE_SCORERS, {
1365
+ const scoreWithId = {
1366
1366
  ...validatedScore,
1367
1367
  id,
1368
1368
  createdAt: now,
1369
1369
  updatedAt: now
1370
- });
1370
+ };
1371
+ const { key, processedRecord } = processRecord(_mastra_core_storage.TABLE_SCORERS, scoreWithId);
1371
1372
  try {
1372
1373
  await this.client.set(key, JSON.stringify(processedRecord));
1373
1374
  return { score: {
@@ -1915,12 +1916,13 @@ var RedisStore = class extends _mastra_core_storage.MastraStorage {
1915
1916
  };
1916
1917
  }
1917
1918
  if (!config.host?.trim()) throw new Error("RedisStore: host is required and cannot be empty.");
1919
+ const url = this.createClientUrl({
1920
+ ...config,
1921
+ db: config.db ?? 0,
1922
+ port: config.port ?? 6379
1923
+ });
1918
1924
  return {
1919
- client: (0, redis.createClient)({ url: this.createClientUrl({
1920
- ...config,
1921
- db: config.db ?? 0,
1922
- port: config.port ?? 6379
1923
- }) }),
1925
+ client: (0, redis.createClient)({ url }),
1924
1926
  shouldManageConnection: true
1925
1927
  };
1926
1928
  }
@@ -1951,11 +1953,12 @@ const defaultEvalScript = (client, script, keys, args) => {
1951
1953
  return client.eval(script, keys.length, ...keys, ...args);
1952
1954
  };
1953
1955
  /**
1954
- * Atomic "allocate index + append + refresh TTLs" used by `listPushIndexed`.
1956
+ * Atomic "allocate index + append + refresh TTL" used by `listPushIndexed`.
1955
1957
  *
1956
1958
  * KEYS[1] = list key, KEYS[2] = counter key
1957
1959
  * ARGV[1] = JSON-serialized object WITHOUT an `index` property
1958
- * ARGV[2] = TTL in seconds (0 = no expiry)
1960
+ * ARGV[2] = TTL in seconds (0 = no expiry), applied to BOTH keys
1961
+
1959
1962
  *
1960
1963
  * The index is spliced into the JSON text as the first property rather than
1961
1964
  * decoded/re-encoded with cjson, which would silently alter large integers
@@ -2066,24 +2069,41 @@ var RedisServerCache = class extends _mastra_core_cache.MastraServerCache {
2066
2069
  }
2067
2070
  /**
2068
2071
  * Single round-trip index allocation + list append + TTL refresh via Lua.
2069
- * This is the durable stream per-chunk hot path (issue #22477): the composed
2070
- * default costs four awaited commands (INCR, EXPIRE, RPUSH, EXPIRE).
2072
+ * This is the durable stream per-chunk hot path (issue #22477).
2071
2073
  */
2072
- async listPushIndexed(listKey, counterKey, value) {
2073
- if (this.scriptingDisabled) return super.listPushIndexed(listKey, counterKey, value);
2074
+ async listPushIndexed(listKey, counterKey, value, ttlMs) {
2075
+ const ttlSeconds = this.ttlSeconds > 0 ? Math.max(this.ttlSeconds, Math.ceil((ttlMs ?? 0) / 1e3)) : 0;
2076
+ if (this.scriptingDisabled) return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
2074
2077
  const { index: _ignored, ...body } = value;
2075
2078
  try {
2076
- const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(this.ttlSeconds)]);
2079
+ const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(ttlSeconds)]);
2077
2080
  return Number(result);
2078
2081
  } catch (error) {
2079
2082
  if (error instanceof Error && error.message.includes("CROSSSLOT")) {
2080
2083
  this.scriptingDisabled = true;
2081
2084
  this.logger.warn("[RedisServerCache] listPushIndexed script rejected with CROSSSLOT; falling back to increment + listPush");
2082
- return super.listPushIndexed(listKey, counterKey, value);
2085
+ return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
2083
2086
  }
2084
2087
  throw error;
2085
2088
  }
2086
2089
  }
2090
+ /**
2091
+ * `INCR` then `RPUSH`, each followed by the same `EXPIRE` the script applies.
2092
+ * Not atomic: concurrent writers can interleave, so a list position may not
2093
+ * match its index (Redis Cluster atomicity is tracked in COR-1491).
2094
+ */
2095
+ async composedPushIndexed(listKey, counterKey, value, ttlSeconds) {
2096
+ const fullCounterKey = this.getKey(counterKey);
2097
+ const index = await this.client.incr(fullCounterKey) - 1;
2098
+ if (ttlSeconds > 0) await this.client.expire(fullCounterKey, ttlSeconds);
2099
+ const fullListKey = this.getKey(listKey);
2100
+ await this.pushToList(this.client, fullListKey, this.serialize({
2101
+ ...value,
2102
+ index
2103
+ }));
2104
+ if (ttlSeconds > 0) await this.client.expire(fullListKey, ttlSeconds);
2105
+ return index;
2106
+ }
2087
2107
  };
2088
2108
  const upstashPreset = {
2089
2109
  setWithExpiry: (client, key, value, seconds) => client.set(key, value, { ex: seconds }),