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: 0 additions & 3 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
Job:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Release

on:
push:
branches: [ master ]
branches: [master]

jobs:
release:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
142 changes: 142 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"env": {
"node": true,
"mocha": true
},
"categories": {
"correctness": "error",
"perf": "error",
"nursery": "error",
"restriction": "error",
"style": "error",
"pedantic": "error",
"suspicious": "error"
},
"plugins": [
"import",
"typescript",
"unicorn",
"jsdoc",
"node",
"promise",
"oxc"
],
"rules": {
// eslint
"constructor-super": "error",
"getter-return": "error",
"no-undef": "error",
"no-unreachable": "error",
"no-var": "error",
"no-eq-null": "error",
"no-await-in-loop": "allow",
"eqeqeq": ["error", "smart"],
"init-declarations": "allow",
"curly": "allow",
"no-ternary": "allow",
"max-params": ["error", 5],
"no-await-expression-member": "error",
"no-continue": "allow",
"guard-for-in": "allow",
"func-style": "allow",
"sort-imports": "allow",
"yoda": "allow",
"sort-keys": "allow",
"no-magic-numbers": "allow",
"no-duplicate-imports": "error",
"no-multi-assign": "error",
"func-names": "error",
"default-param-last": "error",
"prefer-object-spread": "error",
"no-undefined": "allow",
"no-plusplus": "allow",
// maybe warn
"no-console": "warn",
"no-extraneous-class": "allow",
"no-empty-function": "error",
"max-depth": ["error", 6],
"max-lines-per-function": "allow",
"no-lonely-if": "error",
"max-lines": "allow",
"require-await": "allow",
"max-nested-callbacks": ["error", 5],
"max-classes-per-file": "allow",
"radix": "allow",
"no-negated-condition": "error",
"no-else-return": "error",
"no-throw-literal": "error",

// import
"import/exports-last": "allow",
"import/max-dependencies": "allow",
"import/no-cycle": "error",
"import/no-anonymous-default-export": "allow",
"import/no-namespace": "error",
"import/named": "error",
"import/export": "error",
"import/no-default-export": "allow",
"import/unambiguous": "error",

// promise
"promise/no-return-wrap": "error",
"promise/param-names": "error",
"promise/prefer-await-to-callbacks": "error",
"promise/prefer-await-to-then": "error",
"promise/prefer-catch": "error",
"promise/no-return-in-finally": "error",
"promise/avoid-new": "error",

// unicorn
"unicorn/error-message": "error",
"unicorn/no-null": "allow",
"unicorn/filename-case": "allow",
"unicorn/prefer-structured-clone": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-string-slice": "error",
// "unicorn/no-null": "error",
"unicorn/throw-new-error": "error",
"unicorn/catch-error-name": "allow",
"unicorn/prefer-spread": "allow",
"unicorn/numeric-separators-style": "error",
"unicorn/prefer-string-raw": "error",
"unicorn/text-encoding-identifier-case": "error",
"unicorn/no-array-for-each": "error",
"unicorn/explicit-length-check": "error",
"unicorn/no-lonely-if": "error",
"unicorn/no-useless-undefined": "allow",
"unicorn/prefer-date-now": "error",
"unicorn/no-static-only-class": "allow",
"unicorn/no-typeof-undefined": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/no-anonymous-default-export": "allow",

// oxc
"oxc/no-map-spread": "error",
"oxc/no-rest-spread-properties": "allow",
"oxc/no-optional-chaining": "allow",
"oxc/no-async-await": "allow",

// typescript
"typescript/explicit-function-return-type": "allow",
"typescript/consistent-type-imports": "error",
"typescript/consistent-type-definitions": "error",
"typescript/consistent-indexed-object-style": "allow",
"typescript/no-inferrable-types": "error",
"typescript/array-type": "error",
"typescript/no-non-null-assertion": "error",
"typescript/no-explicit-any": "error",
"typescript/no-import-type-side-effects": "error",
"typescript/no-dynamic-delete": "error",
"typescript/prefer-ts-expect-error": "error",
"typescript/ban-ts-comment": "error",
"typescript/prefer-enum-initializers": "error",

// jsdoc
"jsdoc/require-returns": "allow",
"jsdoc/require-param": "allow"
},
"ignorePatterns": ["index.d.ts", "test/fixtures/**", "__snapshots__"]
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHANGELOG.md
__snapshots__
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"arrowParens": "avoid"
}
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ Configure redis information in `${app_root}/config/config.default.js`:
```javascript
config.redis = {
client: {
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: 'auth',
db: 0,
},
}
};
```

**Multi Clients**

```javascript
config.redis = {
clients: {
foo: { // instanceName. See below
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
foo: {
// instanceName. See below
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: 'auth',
db: 0,
},
Expand All @@ -74,8 +75,8 @@ config.redis = {
password: 'auth',
db: 1,
},
}
}
},
};
```

**Sentinel**
Expand All @@ -86,16 +87,16 @@ config.redis = {
// Sentinel instances
sentinels: [
{
port: 26379, // Sentinel port
host: '127.0.0.1', // Sentinel host
port: 26379, // Sentinel port
host: '127.0.0.1', // Sentinel host
},
// other sentinel instance config
],
name: 'mymaster', // Master name
name: 'mymaster', // Master name
password: 'auth',
db: 0
db: 0,
},
}
};
```

**No password**
Expand Down Expand Up @@ -127,26 +128,26 @@ you can pass the instance by `config.redis.Redis`:
config.redis = {
Redis: require('ioredis'), // customize ioredis version, only set when you needed
client: {
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: 'auth',
db: 0,
},
}
};
```

**weakDependent**

```javascript
config.redis = {
client: {
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: 'auth',
db: 0,
weakDependent: true, // the redis instance won't block app start
},
}
};
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion example/hello/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Application } from 'egg';
import type { Application } from 'egg';

export default (app: Application) => {
const { router } = app;
Expand Down
6 changes: 5 additions & 1 deletion example/hello/start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { startEgg } from 'egg';

const __filename = fileURLToPath(import.meta.url);
Expand All @@ -9,4 +10,7 @@ const app = await startEgg({
baseDir: __dirname,
});

console.log(`Server started at http://localhost:${app.config.cluster.listen.port}`);
// oxlint-disable-next-line no-console
console.log(
`Server started at http://localhost:${app.config.cluster.listen.port}`
);
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,44 @@
"node": ">= 18.19.0"
},
"dependencies": {
"@eggjs/core": "^6.3.0",
"@eggjs/core": "^6.4.1",
"ioredis": "^5.4.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@arethetypeswrong/cli": "^0.17.4",
"@eggjs/bin": "7",
"@eggjs/mock": "^6.0.5",
"@eggjs/tsconfig": "1",
"@types/mocha": "10",
"@types/node": "22",
"egg": "^4.0.3",
"eslint": "8",
"eslint-config-egg": "14",
"egg": "4",
"husky": "^9.1.7",
"lint-staged": "^15.5.0",
"oxlint": "^0.16.2",
"prettier": "^3.5.3",
"rimraf": "6",
"snap-shot-it": "^7.9.10",
"tshy": "3",
"tshy-after": "1",
"typescript": "5"
},
"scripts": {
"lint": "eslint --cache src test --ext .ts",
"lint": "oxlint",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"clean": "rimraf dist",
"prepublishOnly": "tshy && tshy-after && attw --pack"
"prepublishOnly": "tshy && tshy-after && attw --pack",
"prepare": "husky"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown --cache",
"*.{ts,js,json,md,yml}": [
"prettier --ignore-unknown --write",
"oxlint --fix"
]
},
"type": "module",
"tshy": {
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RedisOptions, ClusterOptions } from 'ioredis';
import type { RedisOptions, ClusterOptions, Redis } from 'ioredis';

export interface RedisClientOptions extends RedisOptions {
/**
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface RedisConfig {
*
* Default to `undefined`, which means using the built-in ioredis
*/
Redis?: any;
Redis?: typeof Redis;
}

export default {
Expand Down
Loading