@mastra/valkey 0.2.1-alpha.1 → 0.2.2-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 +5 -0
- 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/index.cjs +46 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1654,6 +1654,35 @@ var ValkeyStore = class extends MastraStorage {
|
|
|
1654
1654
|
//#endregion
|
|
1655
1655
|
//#region src/cache.ts
|
|
1656
1656
|
const stringValue = (value) => Buffer.isBuffer(value) ? value.toString() : String(value);
|
|
1657
|
+
/**
|
|
1658
|
+
* Atomic "allocate index + append + refresh TTLs" used by `listPushIndexed`.
|
|
1659
|
+
*
|
|
1660
|
+
* KEYS[1] = list key, KEYS[2] = counter key
|
|
1661
|
+
* ARGV[1] = JSON-serialized object WITHOUT an `index` property
|
|
1662
|
+
* ARGV[2] = TTL in seconds (0 = no expiry)
|
|
1663
|
+
*
|
|
1664
|
+
* The index is spliced into the JSON text as the first property rather than
|
|
1665
|
+
* decoded/re-encoded with cjson, which would silently alter large integers
|
|
1666
|
+
* and sparse arrays. `JSON.stringify` of an object always starts with `{`,
|
|
1667
|
+
* so `{...}` → `{"index":N,...}` and `{}` → `{"index":N}`.
|
|
1668
|
+
*/
|
|
1669
|
+
const LIST_PUSH_INDEXED_SCRIPT = `
|
|
1670
|
+
local i = redis.call('INCR', KEYS[2]) - 1
|
|
1671
|
+
local body = ARGV[1]
|
|
1672
|
+
local doc
|
|
1673
|
+
if #body <= 2 then
|
|
1674
|
+
doc = '{"index":' .. i .. '}'
|
|
1675
|
+
else
|
|
1676
|
+
doc = '{"index":' .. i .. ',' .. string.sub(body, 2)
|
|
1677
|
+
end
|
|
1678
|
+
redis.call('RPUSH', KEYS[1], doc)
|
|
1679
|
+
local ttl = tonumber(ARGV[2])
|
|
1680
|
+
if ttl > 0 then
|
|
1681
|
+
redis.call('EXPIRE', KEYS[1], ttl)
|
|
1682
|
+
redis.call('EXPIRE', KEYS[2], ttl)
|
|
1683
|
+
end
|
|
1684
|
+
return i
|
|
1685
|
+
`.trim();
|
|
1657
1686
|
/** GLIDE-backed Valkey cache for Mastra server state. */
|
|
1658
1687
|
var ValkeyServerCache = class extends MastraServerCache {
|
|
1659
1688
|
client;
|
|
@@ -1751,6 +1780,23 @@ var ValkeyServerCache = class extends MastraServerCache {
|
|
|
1751
1780
|
]);
|
|
1752
1781
|
return value;
|
|
1753
1782
|
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Single round-trip index allocation + list append + TTL refresh via Lua.
|
|
1785
|
+
* This is the durable stream per-chunk hot path (issue #22477).
|
|
1786
|
+
*/
|
|
1787
|
+
async listPushIndexed(listKey, counterKey, value) {
|
|
1788
|
+
const { index: _ignored, ...body } = value;
|
|
1789
|
+
const result = await this.command([
|
|
1790
|
+
"EVAL",
|
|
1791
|
+
LIST_PUSH_INDEXED_SCRIPT,
|
|
1792
|
+
"2",
|
|
1793
|
+
this.getKey(listKey),
|
|
1794
|
+
this.getKey(counterKey),
|
|
1795
|
+
JSON.stringify(body),
|
|
1796
|
+
String(this.ttlSeconds)
|
|
1797
|
+
]);
|
|
1798
|
+
return Number(result);
|
|
1799
|
+
}
|
|
1754
1800
|
};
|
|
1755
1801
|
//#endregion
|
|
1756
1802
|
export { ScoresValkey, StoreMemoryValkey, ValkeyServerCache, ValkeyStore, WorkflowsValkey };
|