Skip to content

Commit 24138ec

Browse files
authored
Update to Redis 4 client and other latest dependencies (#176)
1 parent a34a023 commit 24138ec

File tree

5 files changed

+14793
-1522
lines changed

5 files changed

+14793
-1522
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@ app.configure(
119119
### Redis
120120

121121
- `uri` - The connection string (must start with `redis://`)
122-
- `db` - The Redis database object or connection string (e.g. `redis://localhost:6379`)
123122
- `key` - The key under which all synchronization events will be stored (default: `feathers-sync`)
124123
- `redisClient` - An existing instance of redisClient
125124
- `redisOptions` - Redis [client options](http://redis.js.org/#api-rediscreateclient)
126-
- `subscriberEvent` - The event to listen for. Defaults to `message`. Could be `message_buffer` or `messageBuffer` depending on what Redis library is being used.
127125

128126
### AMQP
129127

lib/adapters/redis.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ const core = require('../core');
44

55
module.exports = config => {
66
return app => {
7-
const { key, serialize, deserialize } = config;
8-
const db = config.uri || config.db;
9-
const { redisClient } = config;
10-
// NOTE: message_buffer (redis) and messageBuffer (ioredis) return buffers
11-
const subscriberEvent = config.subscriberEvent || 'message';
7+
const { key, serialize, deserialize, redisClient, uri } = config;
8+
const options = {
9+
url: uri,
10+
...config.redisOptions
11+
};
1212

13-
if (!redisClient && typeof db !== 'undefined') {
14-
debug(`Setting up Redis client for db: ${db}`);
13+
if (!redisClient) {
14+
debug(`Setting up Redis client for ${options.uri}`);
1515
}
1616

17-
const pub = redisClient || redis.createClient(db, config.redisOptions);
17+
const pub = redisClient || redis.createClient(options);
1818
const sub = pub.duplicate();
1919

2020
app.configure(core);
@@ -25,6 +25,8 @@ module.exports = config => {
2525
sub,
2626
type: 'redis',
2727
ready: new Promise((resolve, reject) => {
28+
pub.connect();
29+
sub.connect();
2830
sub.once('ready', resolve);
2931
sub.once('error', reject);
3032
})
@@ -35,12 +37,9 @@ module.exports = config => {
3537
pub.publish(key, data);
3638
});
3739

38-
sub.subscribe(key);
39-
sub.on(subscriberEvent, function (e, data) {
40-
if (e.toString() === key) {
41-
debug(`Got ${key} message from Redis`);
42-
app.emit('sync-in', data);
43-
}
44-
});
40+
sub.subscribe(key, data => {
41+
debug(`Got ${key} message from Redis`);
42+
app.emit('sync-in', data);
43+
}, true);
4544
};
4645
};

0 commit comments

Comments
 (0)