Skip to content

Commit 15dcec0

Browse files
committed
redis v4 passing
1 parent bb74f84 commit 15dcec0

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2026 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
'use strict'
7+
const ClientPropagationSubscriber = require('./client-propagation')
8+
9+
/**
10+
* Listens to events on RedisClient.commandsExectutor for redis versions <=5.
11+
* Replacement for send-command.js for that version.
12+
*/
13+
module.exports = class ClientCommandsExecutorSubscriber extends ClientPropagationSubscriber {
14+
constructor({ agent, logger }) {
15+
super({ agent, logger, channelName: 'nr_commandsExecutor' })
16+
}
17+
}

lib/subscribers/redis/config.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const addCommand = {
77
path: './redis/add-command',
88
instrumentations: [{
99
channelName: 'nr_addCommand',
10-
module: { name: '@redis/client',
11-
versionRange: '>=4',
12-
filePath: 'dist/lib/client/commands-queue.js' },
10+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/commands-queue.js' },
1311
functionQuery: {
1412
className: 'RedisCommandsQueue',
1513
methodName: 'addCommand',
@@ -38,7 +36,7 @@ const clientSelect = {
3836
instrumentations: [
3937
{
4038
channelName: 'nr_select',
41-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
39+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
4240
functionQuery: {
4341
className: 'RedisClient',
4442
methodName: 'SELECT',
@@ -53,7 +51,7 @@ const clientMulti = {
5351
instrumentations: [
5452
{
5553
channelName: 'nr_multi',
56-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
54+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
5755
functionQuery: {
5856
className: 'RedisClient',
5957
methodName: 'MULTI',
@@ -63,11 +61,27 @@ const clientMulti = {
6361
]
6462
}
6563

64+
const commandsExecutor = {
65+
path: './redis/commands-executor',
66+
instrumentations: [
67+
{
68+
channelName: 'nr_commandsExecutor',
69+
module: { name: '@redis/client', versionRange: '>=1 <4', filePath: 'dist/lib/client/index.js' },
70+
functionQuery: {
71+
className: 'RedisClient',
72+
methodName: 'commandsExecutor',
73+
kind: 'Async'
74+
}
75+
}
76+
]
77+
}
78+
6679
module.exports = {
6780
'@redis/client': [
6881
addCommand,
69-
sendCommand,
82+
sendCommand, // >=v5
7083
clientSelect,
71-
clientMulti
84+
clientMulti,
85+
commandsExecutor // v4
7286
]
7387
}

test/versioned/redis/package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"name": "redis-tests",
3-
"targets": [{"name":"redis","minAgentVersion":"1.31.0"}],
3+
"targets": [
4+
{
5+
"name": "redis",
6+
"minAgentVersion": "1.31.0"
7+
}
8+
],
49
"version": "0.0.0",
510
"private": true,
611
"tests": [
@@ -29,5 +34,8 @@
2934
"tls.test.js"
3035
]
3136
}
32-
]
37+
],
38+
"dependencies": {
39+
"redis": "^4.7.1"
40+
}
3341
}

test/versioned/redis/redis-v4.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test('Redis instrumentation', async function (t) {
5858

5959
await t.test('should log tracking metrics', function(t) {
6060
const { agent } = t.nr
61-
const { version } = require('redis/package.json')
61+
const { version } = require('@redis/client/package.json')
6262
assertPackageMetrics({ agent, pkg: '@redis/client', version, subscriberType: true })
6363
})
6464

0 commit comments

Comments
 (0)