Skip to content

Commit d34145e

Browse files
authored
fix: don't modify options (#54)
1 parent 0946124 commit d34145e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

index.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ const fp = require('fastify-plugin')
44
const Redis = require('ioredis')
55

66
function fastifyRedis (fastify, options, next) {
7-
const namespace = options.namespace
8-
delete options.namespace
9-
let redisUrl
10-
if (options.url) {
11-
redisUrl = options.url
12-
delete options.url
13-
}
7+
const { namespace, url, ...redisOptions } = options
148

159
let client = options.client || null
1610

@@ -29,10 +23,10 @@ function fastifyRedis (fastify, options, next) {
2923

3024
if (!client) {
3125
try {
32-
if (redisUrl) {
33-
client = new Redis(redisUrl, options)
26+
if (url) {
27+
client = new Redis(url, redisOptions)
3428
} else {
35-
client = new Redis(options)
29+
client = new Redis(redisOptions)
3630
}
3731
} catch (err) {
3832
return next(err)
@@ -48,10 +42,10 @@ function fastifyRedis (fastify, options, next) {
4842
} else {
4943
if (!client) {
5044
try {
51-
if (redisUrl) {
52-
client = new Redis(redisUrl, options)
45+
if (url) {
46+
client = new Redis(url, redisOptions)
5347
} else {
54-
client = new Redis(options)
48+
client = new Redis(redisOptions)
5549
}
5650
} catch (err) {
5751
return next(err)

0 commit comments

Comments
 (0)