Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-monorepo-parallel/llms.txt
Use this file to discover all available pages before exploring further.
BaseMap wraps ioredis with a namespaced key pattern and an optional TTL, giving you a production-safe Redis key-value store in one class extension. All keys are stored as <connectionKey>:<key>, so multiple BaseMap instances never collide in the same Redis database. Extending it takes one class and one DI registration — no Redis configuration changes required.
Constructor signature
| Parameter | Type | Description |
|---|---|---|
connectionKey | string | Namespace prefix for all keys in this map. Keys are stored as <connectionKey>:<key>. |
ttlExpireSeconds | number | Seconds before each key expires. Pass -1 for no expiry. Defaults to 300 (5 minutes). |
Creating a cache service
ExtendBaseMap with your chosen namespace and TTL. The di-factory factory() wrapper used internally by BaseMap means your subclass participates in the same lazy-injection lifecycle as every other @pro/core service:
-1:
Available methods
Every class that extendsBaseMap inherits the following methods. All methods operate exclusively on keys within the connectionKey namespace — they never touch keys belonging to other BaseMap instances.
set(key, value) — store a value
set(key, value) — store a value
value under <connectionKey>:<key>. If ttlExpireSeconds is not -1, a Redis EXPIRE is set immediately after the write. Throws if key is an empty string.get(key) — retrieve a value
get(key) — retrieve a value
null if the key does not exist or key is null. Values are returned as strings — deserialize as needed.delete(key) — remove a key
delete(key) — remove a key
<connectionKey>:<key> from Redis. A no-op if the key does not exist.has(key) — check existence
has(key) — check existence
true if the key exists (and has not expired), false otherwise.clear() — remove all keys in the namespace
clear() — remove all keys in the namespace
<connectionKey>:* using a SCAN loop. Safe for large keyspaces — never calls FLUSHALL or FLUSHDB.toArray() — snapshot all key-value pairs
toArray() — snapshot all key-value pairs
[key, value] pairs in the namespace as an in-memory array. Keys have the namespace prefix stripped — you get back "BTCUSDT", not "price-alerts:BTCUSDT".iterate() — async iteration over key-value pairs
iterate() — async iteration over key-value pairs
[key, value] pairs one batch at a time (batch size: 100). Use this instead of toArray() when the namespace may contain thousands of keys.keys() — async iteration over keys only
keys() — async iteration over keys only
values() — async iteration over values only
values() — async iteration over values only
size() — count keys in the namespace
size() — count keys in the namespace
SCAN-based iteration
All iteration methods —clear(), toArray(), iterate(), keys(), values(), and size() — use a SCAN cursor loop with a batch size of 100 (the ITERATOR_BATCH_SIZE constant in BaseMap.ts). This means:
- They never block the Redis event loop, even against keyspaces with millions of keys.
- They are safe to call concurrently from multiple async contexts (the 9 parallel symbol runners all share the same
ioredisclient). - Each batch issues one
SCANcommand and oneMGETfor the found keys — no per-key round-trips.
Redis connection
BaseMap obtains its ioredis client by calling getRedis() from @backtest-kit/mongo. This returns the shared Redis client configured via environment variables:
BaseMap subclass — it reuses the same connection pool.
Registering the cache service
Follow the five-step DI registration recipe from Adding a New Service:- The service file already exists from the step above.
- Add
priceAlertCacheService: Symbol('priceAlertCacheService')totypes.ts. - Add
provide(TYPES.priceAlertCacheService, () => new PriceAlertCacheService())toprovide.ts. - Add
priceAlertCacheService: inject<PriceAlertCacheService>(TYPES.priceAlertCacheService)toiocinlib/index.ts. - Run
npm run build.
core.priceAlertCacheService is globally typed and accessible from strategy files:
Pass
-1 as ttlExpireSeconds for permanent cache entries — for example, candle data that has been pre-warmed with --cache and should not expire mid-run. Pass a positive number for volatile data like current prices, session state, or any value that must be refreshed on a schedule.