Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .connect() as is now required #34

Merged
merged 1 commit into from
May 23, 2022
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
4 changes: 1 addition & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ env:
node: true
es6: true
mocha: true
es2020: true

plugins: [ haraka ]

extends: [ eslint:recommended, plugin:haraka/recommended ]

root: true

parserOptions:
ecmaVersion: 2020

globals:
OK: true
CONT: true
Expand Down
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@


### 2.0.1 - 2022-05-23
### 2.0.2 - 2022-05-23

- fix: rename p* methods -> * (required in redis v4)
- fix: add `await ...connect()` as is now required, fixes #32
- dep(redis): bump 4.0 -> 4.1


Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ exports.redis_subscribe_pattern = async function (pattern) {
if (this.redis) return // already subscribed?

this.redis = await redis.createClient(this.redisCfg.pubsub)
await this.redis.connect()

await this.redis.subscribe(pattern);
this.logdebug(this, `subscribed to ${pattern}`);
await this.redis.pSubscribe(pattern);
this.logdebug(this, `pSubscribed to ${pattern}`);
}

exports.redis_subscribe = async function (connection, event) {
exports.redis_subscribe = async function (connection) {

if (connection.notes.redis) {
connection.logdebug(this, `redis already subscribed`);
Expand All @@ -211,12 +212,13 @@ exports.redis_subscribe = async function (connection, event) {
}, 3 * 1000);

connection.notes.redis = await redis.createClient(this.redisCfg.pubsub)
await connection.notes.redis.connect()

clearTimeout(timer);

const pattern = this.get_redis_sub_channel(connection)
connection.notes.redis.subscribe(pattern, event);
connection.logdebug(this, `subscribed to ${pattern}`);
connection.notes.redis.pSubscribe(pattern);
connection.logdebug(this, `pSubscribed to ${pattern}`);
}

exports.redis_unsubscribe = async function (connection) {
Expand All @@ -229,5 +231,5 @@ exports.redis_unsubscribe = async function (connection) {
const pattern = this.get_redis_sub_channel(connection)
await connection.notes.redis.unsubscribe(pattern);
connection.logdebug(this, `unsubsubscribed from ${pattern}`);
connection.notes.redis.disconnect();
connection.notes.redis.quit();
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-redis",
"version": "2.0.1",
"version": "2.0.2",
"description": "Redis plugin for Haraka & other plugins to inherit from",
"main": "index.js",
"directories": {
Expand All @@ -10,10 +10,10 @@
"redis": "^4.1.0"
},
"devDependencies": {
"eslint": "^8.12.0",
"eslint": "8",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"mocha": "^9.2.0"
"mocha": "9"
},
"scripts": {
"lint": "npx eslint *.js test/*.js",
Expand Down