interface StorageAdapter {
get(sessionToken: string): Promise<DeviceProfile | null>;
set(sessionToken: string, profile: DeviceProfile, ttlSeconds: number): Promise<void>;
delete(sessionToken: string): Promise<void>;
exists(sessionToken: string): Promise<boolean>;
}In-memory storage using a Map with TTL-based expiry. Suitable for development and single-process deployments.
import { MemoryStorageAdapter } from '@device-router/storage';
const storage = new MemoryStorageAdapter();clear(): void— Removes all stored profiles
Redis-backed storage using SET ... EX for TTL. Suitable for production multi-process deployments.
import Redis from 'ioredis';
import { RedisStorageAdapter } from '@device-router/storage';
const storage = new RedisStorageAdapter({
client: new Redis(),
keyPrefix: 'dr:profile:', // Default prefix
});| Option | Type | Default | Description |
|---|---|---|---|
client |
Redis-compatible client | required | Must implement get, set, del, exists |
keyPrefix |
string |
'dr:profile:' |
Key prefix for Redis keys |
All methods catch errors gracefully instead of throwing. If Redis is unavailable or returns corrupted data:
get()returnsnull(treated as no stored profile)exists()returnsfalseset()silently fails (the probe will re-run next session)delete()silently fails (the key will expire via TTL)
This ensures middleware continues to work when Redis is temporarily down — requests proceed without a device profile rather than crashing.