@mastra/redis 1.2.0 → 1.2.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/index.js CHANGED
@@ -1799,12 +1799,24 @@ var defaultSetWithExpiry = (client, key, value, seconds) => {
1799
1799
  var defaultScanKeys = (client, cursor, pattern, count) => {
1800
1800
  return client.scan(cursor, "MATCH", pattern, "COUNT", count);
1801
1801
  };
1802
+ var defaultGetListLength = (client, key) => {
1803
+ return client.llen(key);
1804
+ };
1805
+ var defaultPushToList = (client, key, value) => {
1806
+ return client.rpush(key, value);
1807
+ };
1808
+ var defaultGetListRange = (client, key, start, stop) => {
1809
+ return client.lrange(key, start, stop);
1810
+ };
1802
1811
  var RedisServerCache = class extends MastraServerCache {
1803
1812
  client;
1804
1813
  keyPrefix;
1805
1814
  ttlSeconds;
1806
1815
  setWithExpiry;
1807
1816
  scanKeys;
1817
+ getListLength;
1818
+ pushToList;
1819
+ getListRange;
1808
1820
  constructor(config, options = {}) {
1809
1821
  super({ name: "RedisServerCache" });
1810
1822
  this.client = config.client;
@@ -1812,6 +1824,9 @@ var RedisServerCache = class extends MastraServerCache {
1812
1824
  this.ttlSeconds = options.ttlSeconds ?? 300;
1813
1825
  this.setWithExpiry = options.setWithExpiry ?? defaultSetWithExpiry;
1814
1826
  this.scanKeys = options.scanKeys ?? defaultScanKeys;
1827
+ this.getListLength = options.getListLength ?? defaultGetListLength;
1828
+ this.pushToList = options.pushToList ?? defaultPushToList;
1829
+ this.getListRange = options.getListRange ?? defaultGetListRange;
1815
1830
  }
1816
1831
  getKey(key) {
1817
1832
  return `${this.keyPrefix}${key}`;
@@ -1850,19 +1865,19 @@ var RedisServerCache = class extends MastraServerCache {
1850
1865
  }
1851
1866
  async listLength(key) {
1852
1867
  const fullKey = this.getKey(key);
1853
- return this.client.llen(fullKey);
1868
+ return this.getListLength(this.client, fullKey);
1854
1869
  }
1855
1870
  async listPush(key, value) {
1856
1871
  const fullKey = this.getKey(key);
1857
1872
  const serialized = this.serialize(value);
1858
- await this.client.rpush(fullKey, serialized);
1873
+ await this.pushToList(this.client, fullKey, serialized);
1859
1874
  if (this.ttlSeconds > 0) {
1860
1875
  await this.client.expire(fullKey, this.ttlSeconds);
1861
1876
  }
1862
1877
  }
1863
1878
  async listFromTo(key, from, to = -1) {
1864
1879
  const fullKey = this.getKey(key);
1865
- const values = await this.client.lrange(fullKey, from, to);
1880
+ const values = await this.getListRange(this.client, fullKey, from, to);
1866
1881
  return values.map((v) => this.deserialize(v));
1867
1882
  }
1868
1883
  async delete(key) {
@@ -1891,7 +1906,10 @@ var upstashPreset = {
1891
1906
  };
1892
1907
  var nodeRedisPreset = {
1893
1908
  setWithExpiry: (client, key, value, seconds) => client.set(key, value, { EX: seconds }),
1894
- scanKeys: (client, cursor, pattern, count) => client.scan(cursor, { MATCH: pattern, COUNT: count })
1909
+ scanKeys: (client, cursor, pattern, count) => client.scan(cursor, { MATCH: pattern, COUNT: count }),
1910
+ getListLength: (client, key) => client.lLen(key),
1911
+ pushToList: (client, key, value) => client.rPush(key, value),
1912
+ getListRange: (client, key, start, stop) => client.lRange(key, start, stop)
1895
1913
  };
1896
1914
 
1897
1915
  export { RedisServerCache, RedisStore, ScoresRedis, StoreMemoryRedis, WorkflowsRedis, nodeRedisPreset, upstashPreset };