(config: PubSubChannelConfig)
| 138 | } |
| 139 | |
| 140 | export function createPubSubChannel<T>(config: PubSubChannelConfig): PubSubChannel<T> { |
| 141 | const redisUrl = env.REDIS_URL |
| 142 | if (!redisUrl) return new LocalPubSubChannel<T>(config) |
| 143 | |
| 144 | // Resolve config-derived defaults outside the try so a missing |
| 145 | // REDIS_TLS_SERVERNAME (config error) surfaces instead of silently degrading |
| 146 | // to the in-process EventEmitter — that would break cross-replica pub/sub. |
| 147 | const connectionDefaults = getRedisConnectionDefaults(redisUrl) |
| 148 | |
| 149 | try { |
| 150 | logger.info(`${config.label}: Using Redis`) |
| 151 | return new RedisPubSubChannel<T>(redisUrl, connectionDefaults, config) |
| 152 | } catch (err) { |
| 153 | logger.error(`Failed to create Redis ${config.label}, falling back to local:`, err) |
| 154 | return new LocalPubSubChannel<T>(config) |
| 155 | } |
| 156 | } |
no test coverage detected