Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ const fp = require('fastify-plugin')
const Redis = require('ioredis')

function fastifyRedis (fastify, options, next) {
const namespace = options.namespace
delete options.namespace
let redisUrl
if (options.url) {
redisUrl = options.url
delete options.url
}
const { namespace, url, ...redisOptions } = options

let client = options.client || null

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

if (!client) {
try {
if (redisUrl) {
client = new Redis(redisUrl, options)
if (url) {
client = new Redis(url, redisOptions)
} else {
client = new Redis(options)
client = new Redis(redisOptions)
}
} catch (err) {
return next(err)
Expand All @@ -48,10 +42,10 @@ function fastifyRedis (fastify, options, next) {
} else {
if (!client) {
try {
if (redisUrl) {
client = new Redis(redisUrl, options)
if (url) {
client = new Redis(url, redisOptions)
} else {
client = new Redis(options)
client = new Redis(redisOptions)
}
} catch (err) {
return next(err)
Expand Down