Skip to content

Commit 9ef0ca5

Browse files
committed
feat: integrated hideMeta option to debug log output, modernize repo, bump deps
1 parent 57ce400 commit 9ef0ca5

17 files changed

+212
-7537
lines changed

.commitlintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional']
3+
};

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.*.js

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto
1+
* text=auto eol=lf

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
os:
11+
- ubuntu-latest
12+
node_version:
13+
- 14
14+
- 16
15+
- 18
16+
name: Node ${{ matrix.node_version }} on ${{ matrix.os }}
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Setup node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ matrix.node_version }}
23+
- name: Install dependencies
24+
run: npm install
25+
- name: Run tests
26+
run: npm run test

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
node_modules
55
coverage
66
.nyc_output
7+
locales/
8+
package-lock.json
9+
yarn.lock
10+
11+
Thumbs.db
12+
tmp/
13+
temp/
14+
*.lcov
15+
.env

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit $1

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install lint-staged && npm test

.lintstagedrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
"*.md": filenames => filenames.map(filename => `remark ${filename} -qfo`),
3+
'package.json': 'fixpack',
4+
'*.js': 'xo --fix'
5+
};

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
singleQuote: true,
3+
bracketSpacing: true,
4+
trailingComma: 'none'
5+
};

.remarkrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
plugins: ['preset-github']
3+
};

.xo-config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
prettier: true,
3+
space: true,
4+
extends: ['xo-lass']
5+
};

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# [**@ladjs/redis**](https://github.com/ladjs/redis)
22

3-
[![build status](https://img.shields.io/travis/ladjs/redis.svg)](https://travis-ci.org/ladjs/redis)
4-
[![code coverage](https://img.shields.io/codecov/c/github/ladjs/redis.svg)](https://codecov.io/gh/ladjs/redis)
3+
[![build status](https://github.com/ladjs/redis/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/redis/actions/workflows/ci.yml)
54
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
65
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
76
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
@@ -26,12 +25,6 @@
2625
npm install @ladjs/redis
2726
```
2827

29-
[yarn][]:
30-
31-
```sh
32-
yarn add @ladjs/redis
33-
```
34-
3528

3629
## Usage
3730

@@ -48,10 +41,8 @@ yarn add @ladjs/redis
4841
[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)
4942

5043

51-
##
44+
##
5245

5346
[npm]: https://www.npmjs.com/
5447

55-
[yarn]: https://yarnpkg.com/
56-
5748
[redis]: https://github.com/luin/ioredis

index.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
const IORedis = require('ioredis');
22

3-
function getMeta(client) {
3+
function getMeta(client, hideMeta) {
44
return {
55
description: client._getDescription(),
6-
status: client.status || '[empty]'
6+
status: client.status || '[empty]',
7+
...(hideMeta ? { [hideMeta]: true } : {})
78
};
89
}
910

10-
function bindEvents(client, logger) {
11+
function bindEvents(client, logger, hideMeta) {
1112
client.on('connect', () =>
12-
logger.debug('redis connection established', getMeta(client))
13+
logger.debug('redis connection established', getMeta(client, hideMeta))
1314
);
1415
client.on('ready', () =>
15-
logger.debug('redis connection ready', getMeta(client))
16+
logger.debug('redis connection ready', getMeta(client, hideMeta))
1617
);
17-
client.on('error', (err) => logger.error(err, getMeta(client)));
18+
client.on('error', (error) => logger.error(error, getMeta(client, hideMeta)));
1819
client.on('close', () =>
19-
logger.debug('redis connection closed', getMeta(client))
20+
logger.debug('redis connection closed', getMeta(client, hideMeta))
2021
);
2122
client.on('reconnecting', (time) =>
22-
logger.debug('redis reconnecting', { time, ...getMeta(client) })
23+
logger.debug('redis reconnecting', { time, ...getMeta(client, hideMeta) })
2324
);
2425
client.on('end', () =>
25-
logger.debug('redis connection ended', getMeta(client))
26+
logger.debug('redis connection ended', getMeta(client, hideMeta))
2627
);
2728
client.on('+node', () =>
28-
logger.debug('redis node connected', getMeta(client))
29+
logger.debug('redis node connected', getMeta(client, hideMeta))
2930
);
3031
client.on('-node', () =>
31-
logger.debug('redis node disconnected', getMeta(client))
32+
logger.debug('redis node disconnected', getMeta(client, hideMeta))
3233
);
33-
client.on('node error', (err, address) =>
34-
logger.error(err, { address, ...getMeta(client) })
34+
client.on('node error', (error, address) =>
35+
logger.error(error, { address, ...getMeta(client, hideMeta) })
3536
);
3637
}
3738

@@ -41,33 +42,40 @@ function Redis(
4142
logger = console,
4243
monitor = false,
4344
maxListeners = 15,
44-
_bindEvents = true
45+
_bindEvents = true,
46+
hideMeta = 'hide_meta'
4547
) {
4648
const client = new IORedis(config);
4749
client.setMaxListeners(maxListeners);
4850
// https://github.com/luin/ioredis#monitor
4951
if (monitor) {
50-
client.monitor((err, monitor) => {
51-
if (err) return logger.error(err, getMeta(client));
52+
client.monitor((error, monitor) => {
53+
if (error) {
54+
return logger.error(error, getMeta(client, hideMeta));
55+
}
56+
5257
logger.debug('redis monitor instance created', {
53-
...getMeta(client),
58+
...getMeta(client, hideMeta),
5459
monitor
5560
});
5661
client._monitor = monitor;
5762
monitor.on('monitor', (time, args, source, database) =>
5863
logger.debug('redis monitor', {
59-
...getMeta(client),
64+
...getMeta(client, hideMeta),
6065
time,
6166
args,
6267
source,
6368
database
6469
})
6570
);
66-
bindEvents(monitor, logger);
71+
bindEvents(monitor, logger, hideMeta);
6772
});
6873
}
6974

70-
if (_bindEvents) bindEvents(client, logger);
75+
if (_bindEvents) {
76+
bindEvents(client, logger, hideMeta);
77+
}
78+
7179
return client;
7280
}
7381

package.json

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,41 @@
33
"description": "Redis for Lad",
44
"version": "1.0.7",
55
"author": "Nick Baugh <[email protected]> (http://niftylettuce.com/)",
6-
"ava": {
7-
"failFast": true,
8-
"verbose": true
9-
},
106
"bugs": {
117
"url": "https://github.com/ladjs/redis/issues",
128
"email": "[email protected]"
139
},
14-
"commitlint": {
15-
"extends": [
16-
"@commitlint/config-conventional"
17-
]
18-
},
1910
"contributors": [
2011
"Nick Baugh <[email protected]> (http://niftylettuce.com/)"
2112
],
2213
"dependencies": {
23-
"ioredis": "^4.17.3"
14+
"ioredis": "^5.2.4"
2415
},
2516
"devDependencies": {
26-
"@commitlint/cli": "^9.1.1",
27-
"@commitlint/config-conventional": "^9.1.1",
28-
"ava": "^3.10.1",
29-
"codecov": "^3.7.1",
30-
"cross-env": "^7.0.2",
31-
"delay": "^4.4.0",
32-
"eslint": "7.5.0",
33-
"eslint-config-xo-lass": "^1.0.3",
17+
"@commitlint/cli": "^17.3.0",
18+
"@commitlint/config-conventional": "^17.3.0",
19+
"ava": "^5.1.0",
20+
"cross-env": "^7.0.3",
21+
"delay": "^5.0.0",
22+
"eslint": "8.29.0",
23+
"eslint-config-xo-lass": "^2.0.1",
3424
"eslint-plugin-node": "^11.1.0",
35-
"fixpack": "^3.0.6",
36-
"husky": "^4.2.5",
37-
"lint-staged": "^10.2.11",
25+
"fixpack": "^4.0.0",
26+
"husky": "^8.0.2",
27+
"lint-staged": "^13.1.0",
3828
"nyc": "^15.1.0",
39-
"remark-cli": "^8.0.1",
40-
"remark-preset-github": "^2.0.2",
41-
"sinon": "^9.0.2",
42-
"xo": "^0.32.1"
29+
"remark-cli": "^11.0.0",
30+
"remark-preset-github": "^4.0.4",
31+
"sinon": "^15.0.0",
32+
"xo": "^0.53.1"
4333
},
4434
"engines": {
45-
"node": ">=8.3"
35+
"node": ">=14"
4636
},
37+
"files": [
38+
"index.js"
39+
],
4740
"homepage": "https://github.com/ladjs/redis",
48-
"husky": {
49-
"hooks": {
50-
"pre-commit": "lint-staged && npm test",
51-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
52-
}
53-
},
5441
"keywords": [
5542
"agenda",
5643
"api",
@@ -87,49 +74,18 @@
8774
"web"
8875
],
8976
"license": "MIT",
90-
"lint-staged": {
91-
"*.js": [
92-
"xo --fix",
93-
"git add"
94-
],
95-
"*.md": [
96-
"remark . -qfo",
97-
"git add"
98-
],
99-
"package.json": [
100-
"fixpack",
101-
"git add"
102-
]
103-
},
10477
"main": "index.js",
105-
"prettier": {
106-
"singleQuote": true,
107-
"bracketSpacing": true,
108-
"trailingComma": "none"
109-
},
11078
"publishConfig": {
11179
"access": "public"
11280
},
113-
"remarkConfig": {
114-
"plugins": [
115-
"preset-github"
116-
]
117-
},
11881
"repository": {
11982
"type": "git",
12083
"url": "https://github.com/ladjs/redis"
12184
},
12285
"scripts": {
123-
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
124-
"lint": "xo && remark . -qfo",
125-
"test": "npm run lint && npm run test-coverage",
126-
"test-coverage": "cross-env NODE_ENV=test nyc ava"
127-
},
128-
"xo": {
129-
"prettier": true,
130-
"space": true,
131-
"extends": [
132-
"xo-lass"
133-
]
86+
"lint": "xo --fix && remark . -qfo && fixpack",
87+
"prepare": "husky install",
88+
"pretest": "npm run lint",
89+
"test": "cross-env NODE_ENV=test nyc ava"
13490
}
13591
}

0 commit comments

Comments
 (0)