@onlineapps/conn-base-state
v1.0.1
Published
Redis persistent state connector (no TTL) with atomic rebuild for OA Drive microservices
Maintainers
Readme
@onlineapps/conn-base-state
Redis persistent state connector for OA Drive microservices. Unlike conn-base-cache, state keys have no TTL — they persist until explicitly deleted or rebuilt from DB.
Key differences from conn-base-cache
| Feature | conn-base-cache | conn-base-state |
|---------|----------------|-----------------|
| Key prefix | cache:<service>: | state:<service>: |
| TTL | Required (default 3600s) | Never — keys persist |
| Purpose | Temporary caching | Operational state (entitlements, credits) |
| Rebuild | No rebuild concept | rebuildFromDB() — atomic SCAN+DEL+repopulate |
| Retry | Hard cutoff after N attempts | Exponential backoff, never gives up |
Quick Start
const StateConnector = require('@onlineapps/conn-base-state');
const state = new StateConnector({
host: '127.0.0.1',
port: 6379,
serviceName: 'meta'
});
await state.connect();
// Set/get state (no TTL)
await state.set('entitlement:100:1', '1');
const val = await state.get('entitlement:100:1');
// Atomic rebuild from DB
await state.rebuildFromDB(async (pipeline) => {
pipeline.set('entitlement:100:1', '1');
pipeline.sadd('entitlement:100:bundles', '1');
});API
See JSDoc in src/index.js for full documentation.
Testing
npm run test:unitMock connector available for tests:
const { MockStateConnector } = require('@onlineapps/conn-base-state');
const state = new MockStateConnector({ serviceName: 'test' });