Skip to content

Commit a3120d5

Browse files
committed
feat(microservices): add redis client info tag with auto version
1 parent b796a7f commit a3120d5

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

packages/microservices/client/client-redis.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ export class ClientRedis extends ClientProxy<RedisEvents, RedisStatus> {
9393
host: REDIS_DEFAULT_HOST,
9494
port: REDIS_DEFAULT_PORT,
9595
...this.getClientOptions(),
96-
clientInfoTag: this.getClientInfoTag(),
96+
clientInfoTag: this.getOptionsProp(
97+
this.options,
98+
'clientInfoTag',
99+
this.getClientInfoTag(),
100+
),
97101
lazyConnect: true,
98102
});
99103
}

packages/microservices/external/redis.interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export interface IORedisOptions {
3535
*/
3636
connectionName?: string;
3737

38+
/**
39+
* Set a tag to identify the framework using the Redis client library.
40+
* This is appended to the library name (e.g., "ioredis(nestjs_v11.0.0)").
41+
* @link https://redis.io/docs/latest/commands/client-setinfo/
42+
* @default "nestjs_v{version}" (e.g., "nestjs_v11.0.0")
43+
*/
44+
clientInfoTag?: string;
45+
3846
/**
3947
* If set, client will send AUTH command with the value of this option as the first argument when connected.
4048
* This is supported since Redis 6.

packages/microservices/server/server-redis.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ export class ServerRedis extends Server<RedisEvents, RedisStatus> {
116116
port: REDIS_DEFAULT_PORT,
117117
host: REDIS_DEFAULT_HOST,
118118
...this.getClientOptions(),
119-
clientInfoTag: this.getClientInfoTag(),
119+
clientInfoTag: this.getOptionsProp(
120+
this.options,
121+
'clientInfoTag',
122+
this.getClientInfoTag(),
123+
),
120124
lazyConnect: true,
121125
});
122126
}

packages/microservices/test/client/client-redis.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,23 @@ describe('ClientRedis', () => {
390390
);
391391
});
392392
});
393+
394+
describe('createClient', () => {
395+
it('should use default clientInfoTag when not provided', () => {
396+
const clientWithoutTag = new ClientRedis({});
397+
const redisClient = clientWithoutTag.createClient();
398+
399+
expect(redisClient).to.be.ok;
400+
});
401+
402+
it('should use custom clientInfoTag when provided', () => {
403+
const clientWithTag = new ClientRedis({ clientInfoTag: 'my-app' });
404+
const redisClient = clientWithTag.createClient();
405+
406+
expect(redisClient).to.be.ok;
407+
});
408+
});
409+
393410
describe('getClientInfoTag', () => {
394411
it('should return nestjs version tag when package.json is available', () => {
395412
const result = client['getClientInfoTag']();

packages/microservices/test/server/server-redis.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,23 @@ describe('ServerRedis', () => {
289289
expect(handler.calledWith(data)).to.be.true;
290290
});
291291
});
292+
293+
describe('createRedisClient', () => {
294+
it('should use default clientInfoTag when not provided', () => {
295+
const serverWithoutTag = new ServerRedis({});
296+
const redisClient = serverWithoutTag.createRedisClient();
297+
298+
expect(redisClient).to.be.ok;
299+
});
300+
301+
it('should use custom clientInfoTag when provided', () => {
302+
const serverWithTag = new ServerRedis({ clientInfoTag: 'my-app' });
303+
const redisClient = serverWithTag.createRedisClient();
304+
305+
expect(redisClient).to.be.ok;
306+
});
307+
});
308+
292309
describe('getClientInfoTag', () => {
293310
it('should return nestjs version tag when package.json is available', () => {
294311
const result = server['getClientInfoTag']();

0 commit comments

Comments
 (0)