@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/index.js
CHANGED
|
@@ -1952,11 +1952,12 @@ const defaultEvalScript = (client, script, keys, args) => {
|
|
|
1952
1952
|
return client.eval(script, keys.length, ...keys, ...args);
|
|
1953
1953
|
};
|
|
1954
1954
|
/**
|
|
1955
|
-
* Atomic "allocate index + append + refresh
|
|
1955
|
+
* Atomic "allocate index + append + refresh TTL" used by `listPushIndexed`.
|
|
1956
1956
|
*
|
|
1957
1957
|
* KEYS[1] = list key, KEYS[2] = counter key
|
|
1958
1958
|
* ARGV[1] = JSON-serialized object WITHOUT an `index` property
|
|
1959
|
-
* ARGV[2] = TTL in seconds (0 = no expiry)
|
|
1959
|
+
* ARGV[2] = TTL in seconds (0 = no expiry), applied to BOTH keys
|
|
1960
|
+
|
|
1960
1961
|
*
|
|
1961
1962
|
* The index is spliced into the JSON text as the first property rather than
|
|
1962
1963
|
* decoded/re-encoded with cjson, which would silently alter large integers
|
|
@@ -2067,24 +2068,41 @@ var RedisServerCache = class extends MastraServerCache {
|
|
|
2067
2068
|
}
|
|
2068
2069
|
/**
|
|
2069
2070
|
* Single round-trip index allocation + list append + TTL refresh via Lua.
|
|
2070
|
-
* This is the durable stream per-chunk hot path (issue #22477)
|
|
2071
|
-
* default costs four awaited commands (INCR, EXPIRE, RPUSH, EXPIRE).
|
|
2071
|
+
* This is the durable stream per-chunk hot path (issue #22477).
|
|
2072
2072
|
*/
|
|
2073
|
-
async listPushIndexed(listKey, counterKey, value) {
|
|
2074
|
-
|
|
2073
|
+
async listPushIndexed(listKey, counterKey, value, ttlMs) {
|
|
2074
|
+
const ttlSeconds = this.ttlSeconds > 0 ? Math.max(this.ttlSeconds, Math.ceil((ttlMs ?? 0) / 1e3)) : 0;
|
|
2075
|
+
if (this.scriptingDisabled) return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
|
|
2075
2076
|
const { index: _ignored, ...body } = value;
|
|
2076
2077
|
try {
|
|
2077
|
-
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(
|
|
2078
|
+
const result = await this.evalScript(this.client, LIST_PUSH_INDEXED_SCRIPT, [this.getKey(listKey), this.getKey(counterKey)], [this.serialize(body), String(ttlSeconds)]);
|
|
2078
2079
|
return Number(result);
|
|
2079
2080
|
} catch (error) {
|
|
2080
2081
|
if (error instanceof Error && error.message.includes("CROSSSLOT")) {
|
|
2081
2082
|
this.scriptingDisabled = true;
|
|
2082
2083
|
this.logger.warn("[RedisServerCache] listPushIndexed script rejected with CROSSSLOT; falling back to increment + listPush");
|
|
2083
|
-
return
|
|
2084
|
+
return this.composedPushIndexed(listKey, counterKey, value, ttlSeconds);
|
|
2084
2085
|
}
|
|
2085
2086
|
throw error;
|
|
2086
2087
|
}
|
|
2087
2088
|
}
|
|
2089
|
+
/**
|
|
2090
|
+
* `INCR` then `RPUSH`, each followed by the same `EXPIRE` the script applies.
|
|
2091
|
+
* Not atomic: concurrent writers can interleave, so a list position may not
|
|
2092
|
+
* match its index (Redis Cluster atomicity is tracked in COR-1491).
|
|
2093
|
+
*/
|
|
2094
|
+
async composedPushIndexed(listKey, counterKey, value, ttlSeconds) {
|
|
2095
|
+
const fullCounterKey = this.getKey(counterKey);
|
|
2096
|
+
const index = await this.client.incr(fullCounterKey) - 1;
|
|
2097
|
+
if (ttlSeconds > 0) await this.client.expire(fullCounterKey, ttlSeconds);
|
|
2098
|
+
const fullListKey = this.getKey(listKey);
|
|
2099
|
+
await this.pushToList(this.client, fullListKey, this.serialize({
|
|
2100
|
+
...value,
|
|
2101
|
+
index
|
|
2102
|
+
}));
|
|
2103
|
+
if (ttlSeconds > 0) await this.client.expire(fullListKey, ttlSeconds);
|
|
2104
|
+
return index;
|
|
2105
|
+
}
|
|
2088
2106
|
};
|
|
2089
2107
|
const upstashPreset = {
|
|
2090
2108
|
setWithExpiry: (client, key, value, seconds) => client.set(key, value, { ex: seconds }),
|