@mastra/redis 1.4.11 → 1.4.12-alpha.1
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 +35 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -26
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
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
|
@@ -5,7 +5,7 @@ let _mastra_core_storage = require("@mastra/core/storage");
|
|
|
5
5
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
6
6
|
let redis = require("redis");
|
|
7
7
|
let _mastra_core_cache = require("@mastra/core/cache");
|
|
8
|
-
|
|
8
|
+
// src/storage/domains/utils.ts
|
|
9
9
|
/**
|
|
10
10
|
* Generate a Redis key from table name and key parts.
|
|
11
11
|
*
|
|
@@ -49,8 +49,7 @@ function processRecord(tableName, record) {
|
|
|
49
49
|
processedRecord
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
//#region src/storage/db/index.ts
|
|
52
|
+
// src/storage/db/index.ts
|
|
54
53
|
var RedisDB = class {
|
|
55
54
|
client;
|
|
56
55
|
constructor({ client }) {
|
|
@@ -130,8 +129,7 @@ var RedisDB = class {
|
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
};
|
|
133
|
-
|
|
134
|
-
//#region src/storage/domains/run-fencing.ts
|
|
132
|
+
// src/storage/domains/run-fencing.ts
|
|
135
133
|
/**
|
|
136
134
|
* A claim expires after this long without a claim, renewal or release, and a
|
|
137
135
|
* fence this long after it was retired. A running execution renews every few
|
|
@@ -361,8 +359,7 @@ function writeBatch(client, check) {
|
|
|
361
359
|
async function assertRunFence(client, check) {
|
|
362
360
|
if (check) await new FencedWriteBatch(client, check).exec();
|
|
363
361
|
}
|
|
364
|
-
|
|
365
|
-
//#region src/storage/domains/memory/index.ts
|
|
362
|
+
// src/storage/domains/memory/index.ts
|
|
366
363
|
var StoreMemoryRedis = class extends _mastra_core_storage.MemoryStorage {
|
|
367
364
|
supportsPartialThreadUpdate = true;
|
|
368
365
|
client;
|
|
@@ -1293,8 +1290,7 @@ function getMessageScore(message) {
|
|
|
1293
1290
|
const index = typeof message._index === "number" ? message._index : 0;
|
|
1294
1291
|
return createdAtScore * 1e3 + index;
|
|
1295
1292
|
}
|
|
1296
|
-
|
|
1297
|
-
//#region src/storage/domains/scores/index.ts
|
|
1293
|
+
// src/storage/domains/scores/index.ts
|
|
1298
1294
|
/** Returns true when a row matches the multi-tenant scope filters (or none provided). */
|
|
1299
1295
|
function matchesTenancy(row, filters) {
|
|
1300
1296
|
if (filters?.organizationId !== void 0 && row.organizationId !== filters.organizationId) return false;
|
|
@@ -1444,8 +1440,7 @@ var ScoresRedis = class extends _mastra_core_storage.ScoresStorage {
|
|
|
1444
1440
|
};
|
|
1445
1441
|
}
|
|
1446
1442
|
};
|
|
1447
|
-
|
|
1448
|
-
//#region src/storage/domains/workflows/index.ts
|
|
1443
|
+
// src/storage/domains/workflows/index.ts
|
|
1449
1444
|
function parseWorkflowRun(row) {
|
|
1450
1445
|
let parsedSnapshot = row.snapshot;
|
|
1451
1446
|
if (typeof parsedSnapshot === "string") try {
|
|
@@ -1813,16 +1808,14 @@ var WorkflowsRedis = class extends _mastra_core_storage.WorkflowsStorage {
|
|
|
1813
1808
|
}
|
|
1814
1809
|
}
|
|
1815
1810
|
};
|
|
1816
|
-
|
|
1817
|
-
//#region src/storage/utils.ts
|
|
1811
|
+
// src/storage/utils.ts
|
|
1818
1812
|
function isClientConfig(config) {
|
|
1819
1813
|
return "client" in config;
|
|
1820
1814
|
}
|
|
1821
1815
|
function isConnectionStringConfig(config) {
|
|
1822
1816
|
return "connectionString" in config;
|
|
1823
1817
|
}
|
|
1824
|
-
|
|
1825
|
-
//#region src/storage/store.ts
|
|
1818
|
+
// src/storage/store.ts
|
|
1826
1819
|
/**
|
|
1827
1820
|
* Redis storage adapter for Mastra.
|
|
1828
1821
|
*
|
|
@@ -1932,8 +1925,7 @@ var RedisStore = class extends _mastra_core_storage.MastraStorage {
|
|
|
1932
1925
|
return `redis://${config.host}:${config.port || 6379}/${config.db || 0}`;
|
|
1933
1926
|
}
|
|
1934
1927
|
};
|
|
1935
|
-
|
|
1936
|
-
//#region src/cache.ts
|
|
1928
|
+
// src/cache.ts
|
|
1937
1929
|
const defaultSetWithExpiry = (client, key, value, seconds) => {
|
|
1938
1930
|
return client.set(key, value, "EX", seconds);
|
|
1939
1931
|
};
|
|
@@ -1953,11 +1945,12 @@ const defaultEvalScript = (client, script, keys, args) => {
|
|
|
1953
1945
|
return client.eval(script, keys.length, ...keys, ...args);
|
|
1954
1946
|
};
|
|
1955
1947
|
/**
|
|
1956
|
-
* Atomic "allocate index + append + refresh
|
|
1948
|
+
* Atomic "allocate index + append + refresh TTL" used by `listPushIndexed`.
|
|
1957
1949
|
*
|
|
1958
1950
|
* KEYS[1] = list key, KEYS[2] = counter key
|
|
1959
1951
|
* ARGV[1] = JSON-serialized object WITHOUT an `index` property
|
|
1960
|
-
* ARGV[2] = TTL in seconds (0 = no expiry)
|
|
1952
|
+
* ARGV[2] = TTL in seconds (0 = no expiry), applied to BOTH keys
|
|
1953
|
+
|
|
1961
1954
|
*
|
|
1962
1955
|
* The index is spliced into the JSON text as the first property rather than
|
|
1963
1956
|
* decoded/re-encoded with cjson, which would silently alter large integers
|
|
@@ -2068,24 +2061,41 @@ var RedisServerCache = class extends _mastra_core_cache.MastraServerCache {
|
|
|
2068
2061
|
}
|
|
2069
2062
|
/**
|
|
2070
2063
|
* 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).
|
|
2064
|
+
* This is the durable stream per-chunk hot path (issue #22477).
|
|
2073
2065
|
*/
|
|
2074
|
-
async listPushIndexed(listKey, counterKey, value) {
|
|
2075
|
-
|
|
2066
|
+
async listPushIndexed(listKey, counterKey, value, ttlMs) {
|
|
2067
|
+
const ttlSeconds = this.ttlSeconds > 0 ? Math.max(this.ttlSeconds, Math.ceil((ttlMs ?? 0) / 1e3)) : 0;
|
|
2068
|
+
if (this.scriptingDisabled) return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
|
|
2076
2069
|
const { index: _ignored, ...body } = value;
|
|
2077
2070
|
try {
|
|
2078
|
-
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(
|
|
2071
|
+
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(ttlSeconds)]);
|
|
2079
2072
|
return Number(result);
|
|
2080
2073
|
} catch (error) {
|
|
2081
2074
|
if (error instanceof Error && error.message.includes("CROSSSLOT")) {
|
|
2082
2075
|
this.scriptingDisabled = true;
|
|
2083
2076
|
this.logger.warn("[RedisServerCache] listPushIndexed script rejected with CROSSSLOT; falling back to increment + listPush");
|
|
2084
|
-
return
|
|
2077
|
+
return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
|
|
2085
2078
|
}
|
|
2086
2079
|
throw error;
|
|
2087
2080
|
}
|
|
2088
2081
|
}
|
|
2082
|
+
/**
|
|
2083
|
+
* `INCR` then `RPUSH`, each followed by the same `EXPIRE` the script applies.
|
|
2084
|
+
* Not atomic: concurrent writers can interleave, so a list position may not
|
|
2085
|
+
* match its index (Redis Cluster atomicity is tracked in COR-1491).
|
|
2086
|
+
*/
|
|
2087
|
+
async composedPushIndexed(listKey, counterKey, value, ttlSeconds) {
|
|
2088
|
+
const fullCounterKey = this.getKey(counterKey);
|
|
2089
|
+
const index = await this.client.incr(fullCounterKey) - 1;
|
|
2090
|
+
if (ttlSeconds > 0) await this.client.expire(fullCounterKey, ttlSeconds);
|
|
2091
|
+
const fullListKey = this.getKey(listKey);
|
|
2092
|
+
await this.pushToList(this.client, fullListKey, this.serialize({
|
|
2093
|
+
...value,
|
|
2094
|
+
index
|
|
2095
|
+
}));
|
|
2096
|
+
if (ttlSeconds > 0) await this.client.expire(fullListKey, ttlSeconds);
|
|
2097
|
+
return index;
|
|
2098
|
+
}
|
|
2089
2099
|
};
|
|
2090
2100
|
const upstashPreset = {
|
|
2091
2101
|
setWithExpiry: (client, key, value, seconds) => client.set(key, value, { ex: seconds }),
|
|
@@ -2109,7 +2119,6 @@ const nodeRedisPreset = {
|
|
|
2109
2119
|
arguments: args
|
|
2110
2120
|
})
|
|
2111
2121
|
};
|
|
2112
|
-
//#endregion
|
|
2113
2122
|
exports.LIST_PUSH_INDEXED_SCRIPT = LIST_PUSH_INDEXED_SCRIPT;
|
|
2114
2123
|
exports.RedisServerCache = RedisServerCache;
|
|
2115
2124
|
exports.RedisStore = RedisStore;
|