Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(cache): add support for Redis username authentication (#660)
_okarunec40ae57a6e0
diff --git a/.env.example b/.env.exampleindex 5ff564fb2..ad32435bb 100644--- a/.env.example+++ b/.env.example@@ -194,6 +194,7 @@ REDIS_HOST=localhostREDIS_PORT=6379# Fail Redis queue/cache connection attempts after this many ms.REDIS_CONNECT_TIMEOUT_MS=5000+# REDIS_USERNAME=# REDIS_PASSWORD=# =============================================================================diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 53e4e5fdc..517946222 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Added++- **Redis authentication via username.** Added support for `REDIS_USERNAME` to configure the Redis cache connection and BullMQ queue connections that require a username.+## [0.8.11] - 2026-07-08### Addeddiff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex eab39caa2..1909b403d 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -3793,6 +3793,7 @@ Merge-save infrastructure config to `data/.env.generated` (a `0600` secret file)| `database.sslRejectUnauthorized` | boolean | No | — | Only written when `sslEnabled` is true; default true || `redis.enabled` / `.builtIn` | boolean | No | — | `builtIn`+enabled forces `redis` container + profile || `redis.host` / `.port` | string | No | `port` is a string | Defaults `localhost`/`6379` |+| `redis.username` | string | No | — | Redis ACL username || `redis.password` | string | No | secret | Empty keeps existing || `queue.enabled` | boolean | No | — | Writes `QUEUE_ENABLED` || `storage.type` | `'local' \| 's3'` | No | — | `local` drops stale S3 keys; `s3` drops `STORAGE_LOCAL_PATH` |diff --git a/docs/14-migration-guide.md b/docs/14-migration-guide.mdindex f7c81e2ed..9c306ab52 100644--- a/docs/14-migration-guide.md+++ b/docs/14-migration-guide.md@@ -194,6 +194,7 @@ REDIS_ENABLED=trueREDIS_BUILTIN=false # false = external RedisREDIS_HOST=your-redis-host.comREDIS_PORT=6379+REDIS_USERNAME=optionalREDIS_PASSWORD=optional```diff --git a/src/common/cache/cache.service.ts b/src/common/cache/cache.service.tsindex 3aa8a8dbe..e6f27f088 100644--- a/src/common/cache/cache.service.ts+++ b/src/common/cache/cache.service.ts@@ -71,6 +71,7 @@ export class CacheService implements OnModuleDestroy {this.redis = new Redis({host,port,+ username: this.configService.get<string>('REDIS_USERNAME'),password: this.configService.get<string>('REDIS_PASSWORD'),db: this.configService.get<number>('REDIS_CACHE_DB', 1),lazyConnect: true,diff --git a/src/config/configuration.ts b/src/config/configuration.tsindex b0add4d2b..f76bdd546 100644--- a/src/config/configuration.ts+++ b/src/config/configuration.ts@@ -11,6 +11,7 @@ export default () => ({redis: {host: process.env.REDIS_HOST || 'localhost',port: parseInt(process.env.REDIS_PORT || '6379', 10),+ username: process.env.REDIS_USERNAME,password: process.env.REDIS_PASSWORD,connectTimeoutMs: parseInt(process.env.REDIS_CONNECT_TIMEOUT_MS || '5000', 10),},diff --git a/src/modules/queue/queue.module.ts b/src/modules/queue/queue.module.tsindex 439adbfe9..877b17285 100644--- a/src/modules/queue/queue.module.ts+++ b/src/modules/queue/queue.module.ts@@ -34,6 +34,7 @@ export { QUEUE_NAMES } from './queue-names';connection: {host: configService.get<string>('redis.host', 'localhost'),port: configService.get<number>('redis.port', 6379),+ username: configService.get<string>('redis.username'),password: configService.get<string>('redis.password'),connectTimeout: configService.get<number>('redis.connectTimeoutMs', 5000),enableOfflineQueue: false,diff --git a/src/modules/queue/redis-connection.spec.ts b/src/modules/queue/redis-connection.spec.tsindex aee6945bd..cd61dcfb8 100644--- a/src/modules/queue/redis-connection.spec.ts+++ b/src/modules/queue/redis-connection.spec.ts@@ -15,26 +15,30 @@ describe('workerConnectionOptions (webhook Worker connection)', () => {expect(opts.enableOfflineQueue).toBeUndefined();});- it('reads host/port/password/connectTimeout from env with safe defaults', () => {+ it('reads host/port/username/password/connectTimeout from env with safe defaults', () => {process.env = { ...ORIGINAL_ENV };delete process.env.REDIS_HOST;delete process.env.REDIS_PORT;+ delete process.env.REDIS_USERNAME;delete process.env.REDIS_PASSWORD;delete process.env.REDIS_CONNECT_TIMEOUT_MS;expect(workerConnectionOptions()).toEqual({host: 'localhost',port: 6379,+ username: undefined,password: undefined,connectTimeout: 5000,});process.env.REDIS_HOST = 'redis.internal';process.env.REDIS_PORT = '6380';+ process.env.REDIS_USERNAME = 'myuser';process.env.REDIS_PASSWORD = 'secret';process.env.REDIS_CONNECT_TIMEOUT_MS = '1234';expect(workerConnectionOptions()).toEqual({host: 'redis.internal',port: 6380,+ username: 'myuser',password: 'secret',connectTimeout: 1234,});diff --git a/src/modules/queue/redis-connection.ts b/src/modules/queue/redis-connection.tsindex e59204bde..6c62975eb 100644--- a/src/modules/queue/redis-connection.ts+++ b/src/modules/queue/redis-connection.ts@@ -9,13 +9,14 @@* (moveToActive, lock renewal) need to tolerate a brief reconnect during a Redis blip/failover;* BullMQ explicitly recommends leaving the offline queue enabled for Worker connections. Because* @nestjs/bullmq otherwise builds the Worker from the same shared connection, the WebhookProcessor- * overrides its connection with these options — host/port/password/timeout identical to the producer+ * overrides its connection with these options — host/port/username/password/timeout identical to the producer* (same env vars, same defaults as configuration.ts), but with the offline queue left at ioredis's* default of `true` so a transient outage no longer throws "Stream isn't writeable" and stalls jobs.*/export interface WorkerConnectionOptions {host: string;port: number;+ username?: string;password?: string;connectTimeout: number;}@@ -24,6 +25,7 @@ export function workerConnectionOptions(): WorkerConnectionOptions {return {host: process.env.REDIS_HOST || 'localhost',port: parseInt(process.env.REDIS_PORT || '6379', 10),+ username: process.env.REDIS_USERNAME,password: process.env.REDIS_PASSWORD,connectTimeout: parseInt(process.env.REDIS_CONNECT_TIMEOUT_MS || '5000', 10),};