@pwngh/economy-lab
    Preparing search index...

    Function redisCache

    • Adapts an already-connected ioredis client into the Cache the core expects. Values are opaque strings; this adapter never parses them. The caller creates and owns the client (TLS, sentinel, cluster), which also lets a test substitute a fake; the returned close() releases the connection.

      ttlMs maps to Redis's PX flag, so expiry is enforced by Redis itself; a set with no TTL persists until invalidated. Keys live under the economy:cache: prefix, so they never collide with other data in the instance and an operator can find or delete them as a set. A failed call throws a retryable STORE.FAILURE; the cache is best-effort, so callers fall back to the store.

      Parameters

      • client: RedisClient

      Returns Cache & { close(): Promise<void> }

      import Redis from 'ioredis';
      const cache = redisCache(new Redis('redis://localhost:6379'));
      await cache.set('bal:usr_42:spendable', 'CREDIT:12.34', 60_000);
      await cache.get('bal:usr_42:spendable'); // 'CREDIT:12.34' | null past the TTL
      await cache.close();

      Storage for how the cache port backs hot reads.