Skip to content

Commit 61a0daa

Browse files
committed
redis v4 passing
1 parent 024f577 commit 61a0daa

File tree

7 files changed

+76
-61
lines changed

7 files changed

+76
-61
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: 22 additions & 24 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',
@@ -33,45 +31,45 @@ const sendCommand = {
3331
]
3432
}
3533

36-
const executeMulti = {
37-
path: './redis/execute-multi',
34+
const clientSelect = {
35+
path: './redis/select',
3836
instrumentations: [
3937
{
40-
channelName: 'nr_executeMulti',
41-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
38+
channelName: 'nr_select',
39+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
4240
functionQuery: {
4341
className: 'RedisClient',
44-
methodName: '_executeMulti',
42+
methodName: 'SELECT',
4543
kind: 'Async'
4644
}
47-
},
45+
}
4846
]
4947
}
5048

51-
const executePipeline = {
52-
path: './redis/execute-multi',
49+
const clientMulti = {
50+
path: './redis/multi',
5351
instrumentations: [
5452
{
55-
channelName: 'nr_executePipeline',
56-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
53+
channelName: 'nr_multi',
54+
module: { name: '@redis/client', versionRange: '>=1', filePath: 'dist/lib/client/index.js' },
5755
functionQuery: {
5856
className: 'RedisClient',
59-
methodName: '_executePipeline',
60-
kind: 'Async'
57+
methodName: 'MULTI',
58+
kind: 'Sync'
6159
}
62-
},
60+
}
6361
]
6462
}
6563

66-
const clientSelect = {
67-
path: './redis/select',
64+
const commandsExecutor = {
65+
path: './redis/commands-executor',
6866
instrumentations: [
6967
{
70-
channelName: 'nr_select',
71-
module: { name: '@redis/client', versionRange: '>=4', filePath: 'dist/lib/client/index.js' },
68+
channelName: 'nr_commandsExecutor',
69+
module: { name: '@redis/client', versionRange: '>=1 <4', filePath: 'dist/lib/client/index.js' },
7270
functionQuery: {
7371
className: 'RedisClient',
74-
methodName: 'SELECT',
72+
methodName: 'commandsExecutor',
7573
kind: 'Async'
7674
}
7775
}
@@ -81,9 +79,9 @@ const clientSelect = {
8179
module.exports = {
8280
'@redis/client': [
8381
addCommand,
84-
sendCommand,
82+
sendCommand, // >=v5
8583
clientSelect,
86-
executeMulti,
87-
executePipeline
84+
clientMulti,
85+
commandsExecutor // v4
8886
]
8987
}

lib/subscribers/redis/execute-multi.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/subscribers/redis/execute-pipeline.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/subscribers/redis/multi.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
const { redisClientOpts } = require('../../symbols')
9+
10+
/**
11+
* Propagates the context in `RedisClient.MULTI` and
12+
* `RedisClient[redisClientOpts]` into `RedisCommandQueue.addCommand`.
13+
*/
14+
module.exports = class ClientMultiSubscriber extends ClientPropagationSubscriber {
15+
constructor({ agent, logger }) {
16+
super({ agent, logger, channelName: 'nr_multi' })
17+
this.events = ['start']
18+
}
19+
20+
start(data) {
21+
const { self: client } = data
22+
if (!client[redisClientOpts]) {
23+
client[redisClientOpts] = this.getRedisParams(client.options)
24+
}
25+
}
26+
}

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)