Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: node_js

node_js:
- "14"
- "12"
- "10"
- "8"
- "6"

services:
- redis-server
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ function fastifyRedis (fastify, options, next) {
} else {
if (!client) {
try {
client = new Redis(options)
if (redisUrl) {
client = new Redis(redisUrl, options)
} else {
client = new Redis(options)
}
} catch (err) {
return next(err)
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"test": "npm run lint && npm run unit && npm run typescript",
"lint": "standard",
"unit": "tap test.js",
"unit": "tap test/test.js",
"typescript": "tsc --project ./test/types/tsconfig.json",
"redis": "docker run -p 6379:6379 --rm redis:5"
},
Expand All @@ -33,6 +33,7 @@
"@types/ioredis": "^4.0.18",
"@types/node": "^12.11.1",
"fastify": "^2.5.0",
"proxyquire": "^2.1.3",
"redis": "^2.8.0",
"standard": "^14.0.2",
"tap": "^12.7.0"
Expand Down
27 changes: 15 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

const t = require('tap')
const proxyquire = require('proxyquire')
const test = t.test
const Fastify = require('fastify')
const fastifyRedis = require('../index')
const fastifyRedis = require('..')

t.beforeEach((done) => {
const fastify = Fastify()
Expand Down Expand Up @@ -38,26 +39,28 @@ test('fastify.redis should exist', (t) => {
})

test('fastify.redis should support url', (t) => {
t.plan(4)
t.plan(3)
const fastify = Fastify()

const fastifyRedis = proxyquire('..', {
ioredis: function Redis (path, options) {
t.equal(path, 'redis://127.0.0.1')
t.deepEqual(options, {
otherOption: 'foo'
})
this.quit = () => {}
return this
}
})

fastify.register(fastifyRedis, {
url: 'redis://127.0.0.1',
otherOption: 'foo'
})

fastify.ready((err) => {
t.error(err)

fastify.redis.set('key', 'value', (err) => {
t.error(err)
fastify.redis.get('key', (err, val) => {
t.error(err)
t.equal(val, 'value')

fastify.close()
})
})
fastify.close()
})
})

Expand Down