Skip to content

Commit ab08158

Browse files
committed
To maintain backwards compatible.
1 parent 64a22e7 commit ab08158

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Fastify Redis connection plugin, with this you can share the same Redis connection in every part of your server.
66

7-
Under the hood the official [redis](https://github.com/NodeRedis/node_redis) client is used, the ``options`` that you pass to `register` which the ``redis`` option will be passed to the Redis client.
7+
Under the hood the official [redis](https://github.com/NodeRedis/node_redis) client is used, the ``options`` that you pass to `register` will be passed to the Redis client.
88

99
## Install
1010
```
@@ -14,16 +14,14 @@ npm i fastify-redis --save
1414
Add it to you project with `register` and you are done!
1515
You can access the *Redis* client via `fastify.redis`.
1616

17-
And you can custom your own redis client, use ``driver`` option, now only support [ioredis](https://github.com/luin/ioredis) client, default is [redis](https://github.com/NodeRedis/node_redis).
17+
And you can custom your own redis client, use ``driver`` option, now support [ioredis](https://github.com/luin/ioredis) client, default is [redis](https://github.com/NodeRedis/node_redis).
1818

1919
```js
2020
const fastify = require('fastify')
2121

2222
fastify.register(require('fastify-redis'), {
2323
driver: require('ioredis'), // when you custom your redis client. optional
24-
redis: {
25-
host: '127.0.0.1'
26-
}
24+
host: '127.0.0.1'
2725
}, err => {
2826
if (err) throw err
2927
})

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ function fastifyRedis (fastify, options, next) {
77
var client = null
88
try {
99
// if custom redis module, default is redis.
10-
var Redis = options.driver
11-
client = Redis ? new Redis(options.redis) : redis.createClient(options.redis)
10+
const Driver = options.driver
11+
delete options.driver
12+
client = Driver ? new Driver(options) : redis.createClient(options)
1213
} catch (err) {
1314
return next(err)
1415
}

test.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ t.beforeEach(done => {
99
const fastify = Fastify()
1010

1111
fastify.register(fastifyRedis, {
12-
redis: {
13-
host: '127.0.0.1'
14-
}
12+
host: '127.0.0.1'
1513
}, (err) => {
1614
t.error(err)
1715
})
@@ -30,9 +28,7 @@ test('fastify.redis should exist', t => {
3028
t.plan(3)
3129
const fastify = Fastify()
3230
fastify.register(fastifyRedis, {
33-
redis: {
34-
host: '127.0.0.1'
35-
}
31+
host: '127.0.0.1'
3632
}, (err) => {
3733
t.error(err)
3834
})
@@ -50,9 +46,7 @@ test('fastify.redis should be the redis client', t => {
5046
const fastify = Fastify()
5147

5248
fastify.register(fastifyRedis, {
53-
redis: {
54-
host: '127.0.0.1'
55-
}
49+
host: '127.0.0.1'
5650
}, (err) => {
5751
t.error(err)
5852
})
@@ -78,9 +72,7 @@ test('fastify.redis should exist when use the custom redis driver', t => {
7872

7973
fastify.register(fastifyRedis, {
8074
driver: require('ioredis'),
81-
redis: {
82-
host: '127.0.0.1'
83-
}
75+
host: '127.0.0.1'
8476
}, (err) => {
8577
t.error(err)
8678
})
@@ -99,9 +91,7 @@ test('fastify.redis should be the redis client when use the custom redis driver'
9991

10092
fastify.register(fastifyRedis, {
10193
driver: require('ioredis'),
102-
redis: {
103-
host: '127.0.0.1'
104-
}
94+
host: '127.0.0.1'
10595
}, (err) => {
10696
t.error(err)
10797
})

0 commit comments

Comments
 (0)