Skip to content

Commit c98d896

Browse files
authored
Fixes 195 (#196)
Signed-off-by: Matteo Collina <[email protected]>
1 parent 16d4cd9 commit c98d896

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function fastifyRedis (fastify, options, next) {
118118
.on('error', onError)
119119
.on('ready', onReady)
120120

121-
client.ping()
121+
client.ping().catch(onError)
122122
}
123123
}
124124

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "standard",
1010
"lint:fix": "standard --fix",
1111
"redis": "docker run -p 6379:6379 --rm redis",
12+
"valkey": "docker run -p 6379:6379 --rm valkey/valkey:7.2",
1213
"test": "npm run unit && npm run typescript",
1314
"typescript": "tsd",
1415
"unit": "tap",

test/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,35 @@ test('Should throw when @fastify/redis is initialized with a namespace and an op
490490
})
491491
})
492492

493+
test('catch .ping() errors', (t) => {
494+
t.plan(2)
495+
const fastify = Fastify()
496+
497+
const fastifyRedis = proxyquire('..', {
498+
ioredis: function Redis (path, options) {
499+
this.ping = () => {
500+
return Promise.reject(new Redis.ReplyError('ping error'))
501+
}
502+
this.quit = () => {}
503+
this.info = cb => cb(null, 'info')
504+
this.on = function (name, handler) {
505+
return this
506+
}
507+
this.off = function () { return this }
508+
509+
return this
510+
}
511+
})
512+
513+
fastify.register(fastifyRedis)
514+
515+
fastify.ready((err) => {
516+
t.ok(err)
517+
t.equal(err.message, 'ping error')
518+
fastify.close()
519+
})
520+
})
521+
493522
setInterval(() => {
494523
whyIsNodeRunning()
495524
}, 5000).unref()

0 commit comments

Comments
 (0)