@mastra/redis 1.4.11 → 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 +20 -5
- package/dist/cache.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/integrations-databases-redis.md +1 -1
- package/dist/index.cjs +26 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
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
|
|
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)
|
|
75
|
-
|
|
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
|
-
|
|
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'>;
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -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,EA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CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,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"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -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-
|
|
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
|
@@ -1953,11 +1953,12 @@ const defaultEvalScript = (client, script, keys, args) => {
|
|
|
1953
1953
|
return client.eval(script, keys.length, ...keys, ...args);
|
|
1954
1954
|
};
|
|
1955
1955
|
/**
|
|
1956
|
-
* Atomic "allocate index + append + refresh
|
|
1956
|
+
* Atomic "allocate index + append + refresh TTL" used by `listPushIndexed`.
|
|
1957
1957
|
*
|
|
1958
1958
|
* KEYS[1] = list key, KEYS[2] = counter key
|
|
1959
1959
|
* ARGV[1] = JSON-serialized object WITHOUT an `index` property
|
|
1960
|
-
* ARGV[2] = TTL in seconds (0 = no expiry)
|
|
1960
|
+
* ARGV[2] = TTL in seconds (0 = no expiry), applied to BOTH keys
|
|
1961
|
+
|
|
1961
1962
|
*
|
|
1962
1963
|
* The index is spliced into the JSON text as the first property rather than
|
|
1963
1964
|
* decoded/re-encoded with cjson, which would silently alter large integers
|
|
@@ -2068,24 +2069,41 @@ var RedisServerCache = class extends _mastra_core_cache.MastraServerCache {
|
|
|
2068
2069
|
}
|
|
2069
2070
|
/**
|
|
2070
2071
|
* Single round-trip index allocation + list append + TTL refresh via Lua.
|
|
2071
|
-
* This is the durable stream per-chunk hot path (issue #22477)
|
|
2072
|
-
* default costs four awaited commands (INCR, EXPIRE, RPUSH, EXPIRE).
|
|
2072
|
+
* This is the durable stream per-chunk hot path (issue #22477).
|
|
2073
2073
|
*/
|
|
2074
|
-
async listPushIndexed(listKey, counterKey, value) {
|
|
2075
|
-
|
|
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);
|
|
2076
2077
|
const { index: _ignored, ...body } = value;
|
|
2077
2078
|
try {
|
|
2078
|
-
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(
|
|
2079
|
+
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(ttlSeconds)]);
|
|
2079
2080
|
return Number(result);
|
|
2080
2081
|
} catch (error) {
|
|
2081
2082
|
if (error instanceof Error && error.message.includes("CROSSSLOT")) {
|
|
2082
2083
|
this.scriptingDisabled = true;
|
|
2083
2084
|
this.logger.warn("[RedisServerCache] listPushIndexed script rejected with CROSSSLOT; falling back to increment + listPush");
|
|
2084
|
-
return
|
|
2085
|
+
return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
|
|
2085
2086
|
}
|
|
2086
2087
|
throw error;
|
|
2087
2088
|
}
|
|
2088
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
|
+
}
|
|
2089
2107
|
};
|
|
2090
2108
|
const upstashPreset = {
|
|
2091
2109
|
setWithExpiry: (client, key, value, seconds) => client.set(key, value, { ex: seconds }),
|