distributed: {
enabled: true,
redisUrl: process.env.REDIS_URL,
instanceId: process.env.INSTANCE_ID
}const Redis = require('ioredis');
const redis = new Redis('redis://localhost:6379');
const msq = new MonSQLize({
type: 'mongodb',
databaseName: 'mydb',
config: { uri: 'mongodb://...' },
cache: {
multiLevel: true,
local: { maxEntries: 1000 },
remote: MonSQLize.createRedisCacheAdapter(redis), //① Redis cache
distributed: {
enabled: true, //② Enable distributed failure
redis, //③ Pub/Sub connection
instanceId: process.env.INSTANCE_ID //④ Instance ID (recommended setting)
}
}
});| Parameters | Required? | Default value |
|---|---|---|
enabled |
No | true when the block exists |
redis |
Use redis or redisUrl |
Not inferred from remote |
redisUrl |
Use redis or redisUrl |
- |
instanceId |
❌ No | instance-${timestamp}-${random} |
channel |
❌ No | 'monsqlize:cache:invalidate' |
transaction.distributedLock is retained only as a compatibility placeholder. It is not wired into transaction cache-lock interception, and transaction cache locks remain process-local.
For cross-instance critical sections, use explicit business coordination such as DistributedCacheLockManager plus idempotency/fencing, or bypass cache for strict freshness paths.
distributed: {
enabled: true,
redisUrl: process.env.REDIS_URL,
instanceId: process.env.INSTANCE_ID //Use environment variables
}const msq = new MonSQLize({
type: 'mongodb',
databaseName: 'mydb',
cache: {
distributed: {
enabled: true,
redisUrl: process.env.REDIS_URL,
instanceId: process.env.INSTANCE_ID
}
}
});
// Explicit business coordination, not transaction.distributedLock.
const lock = new MonSQLize.DistributedCacheLockManager({
redis,
lockKeyPrefix: 'myapp:business:lock:'
});
await lock.withLock(`payment:${paymentId}`, async () => {
// Idempotent critical section.
});distributed: {
enabled: true,
redisUrl: process.env.REDIS_URL,
instanceId: process.env.HOSTNAME //Use Pod name
}docker run -e INSTANCE_ID=server-1 myappenv:
- name: INSTANCE_ID
valueFrom:
fieldRef:
fieldPath: metadata.name # Use Pod name{
"apps": [{
"name": "app-1",
"script": "server.js",
"env": {
"INSTANCE_ID": "app-1"
}
}]
}redisorredisUrl- required for distributed invalidation; the runtime does not inspectcache.remoteenabled- optional when the block exists; set it tofalseto disable the block without deleting itinstanceId- Optional but recommended setting for easy debugging- Strict cross-instance flows - use explicit business coordination or bypass cache
//Check after startup
const stats = msq.getDistributedCacheInvalidatorStats();
console.log('Distributed invalidator status:', stats);
//Output: { messagesSent: 0, messagesReceived: 0, instanceId: 'xxx', ... }Documentation: Full Description Update: 2025-11-25