-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd1acfc
Showing
25 changed files
with
5,825 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"extends": ["@commitlint/config-angular"], | ||
"rules": { | ||
"subject-case": [ | ||
2, | ||
"always", | ||
["sentence-case", "start-case", "pascal-case", "upper-case", "lower-case"] | ||
], | ||
"type-enum": [ | ||
2, | ||
"always", | ||
[ | ||
"build", | ||
"chore", | ||
"ci", | ||
"docs", | ||
"feat", | ||
"fix", | ||
"perf", | ||
"refactor", | ||
"revert", | ||
"style", | ||
"test", | ||
"sample" | ||
] | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-use-before-define': 'off', | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# compiled output | ||
/dist | ||
/tmp | ||
/out-tsc | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# profiling files | ||
chrome-profiler-events.json | ||
speed-measure-plugin.json | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# misc | ||
/.sass-cache | ||
/connect.lock | ||
/coverage | ||
/libpeerconnection.log | ||
npm-debug.log | ||
yarn-error.log | ||
testem.log | ||
/typings | ||
|
||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Doc | ||
lib/core/metadata.js | ||
lib/core/MetadataBlog.js | ||
website/translated_docs | ||
website/build/ | ||
website/yarn.lock | ||
website/node_modules | ||
website/i18n/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# source | ||
lib | ||
tests | ||
sample | ||
index.ts | ||
package-lock.json | ||
yarn.lock | ||
tsconfig.json | ||
.prettierrc | ||
docs | ||
website | ||
|
||
# misc | ||
.commitlintrc.json | ||
.release-it.json | ||
.eslintignore | ||
.eslintrc.js | ||
renovate.json | ||
.prettierignore | ||
.prettierrc | ||
publish.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/generated-definitions/*.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Nest modules | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<p align="center"> | ||
<a href="http://nestjs.com/" target="blank"> | ||
<img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
A ioredis module for Nest framework (node.js) using <a href="https://github.com/luin/ioredis">ioredis</a> library | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/v/@nestjs-modules/ioredis.svg" alt="NPM Version" /></a> | ||
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/l/@nestjs-modules/ioredis.svg" alt="Package License" /></a> | ||
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/dm/@nestjs-modules/ioredis.svg" alt="NPM Downloads" /></a> | ||
</p> | ||
|
||
### Installation | ||
|
||
#### with npm | ||
```sh | ||
npm install --save @nestjs-modules/ioredis ioredis | ||
``` | ||
|
||
#### with yarn | ||
```sh | ||
yarn add @nestjs-modules/ioredis ioredis | ||
``` | ||
|
||
### How to use? | ||
|
||
#### RedisModule.forRoot(options, connection?) | ||
|
||
```ts | ||
import { Module } from '@nestjs/common'; | ||
import { RedisModule } from '@nestjs-modules/ioredis'; | ||
import { AppController } from './app.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
RedisModule.forRoot({ | ||
config: { | ||
url: 'redis://localhost:6379', | ||
}, | ||
}), | ||
], | ||
controllers: [AppController], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
#### RedisModule.forRootAsync(options, connection?) | ||
|
||
```ts | ||
import { Module } from '@nestjs/common'; | ||
import { RedisModule } from '@nestjs-modules/ioredis'; | ||
import { AppController } from './app.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
RedisModule.forRootAsync({ | ||
useFactory: () => ({ | ||
config: { | ||
url: 'redis://localhost:6379', | ||
}, | ||
}), | ||
}), | ||
], | ||
controllers: [AppController], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
#### InjectRedis(connection?) | ||
|
||
```ts | ||
import { Controller, Get, } from '@nestjs/common'; | ||
import { InjectRedis, Redis } from '@nestjs-modules/ioredis'; | ||
|
||
@Controller() | ||
export class AppController { | ||
constructor( | ||
@InjectRedis() private readonly redis: Redis, | ||
) {} | ||
|
||
@Get() | ||
async getHello() { | ||
await this.redis.set('key', 'Redis data!'); | ||
const redisData = await this.redis.get("key"); | ||
return { redisData }; | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
exports.__esModule = true; | ||
__export(require("./dist")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './redis.module'; | ||
export * from './redis.decorators'; | ||
export * from './redis.interfaces'; | ||
export * from './redis.utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const REDIS_MODULE_CONNECTION = 'default'; | ||
export const REDIS_MODULE_CONNECTION_TOKEN = 'IORedisModuleConnectionToken'; | ||
export const REDIS_MODULE_OPTIONS_TOKEN = 'IORedisModuleOptionsToken'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { DynamicModule, Module, Global, Provider } from '@nestjs/common'; | ||
import { RedisModuleAsyncOptions, RedisModuleOptions, RedisModuleOptionsFactory } from './redis.interfaces'; | ||
import { createRedisConnection, getRedisOptionsToken, getRedisConnectionToken } from './redis.utils' | ||
|
||
@Global() | ||
@Module({}) | ||
export class RedisCoreModule { | ||
|
||
/* forRoot */ | ||
static forRoot(options: RedisModuleOptions, connection?: string): DynamicModule { | ||
|
||
const redisOptionsProvider: Provider = { | ||
provide: getRedisOptionsToken(connection), | ||
useValue: options, | ||
}; | ||
|
||
const redisConnectionProvider: Provider = { | ||
provide: getRedisConnectionToken(connection), | ||
useValue: createRedisConnection(options), | ||
}; | ||
|
||
return { | ||
module: RedisCoreModule, | ||
providers: [ | ||
redisOptionsProvider, | ||
redisConnectionProvider, | ||
], | ||
exports: [ | ||
redisOptionsProvider, | ||
redisConnectionProvider, | ||
], | ||
}; | ||
} | ||
|
||
/* forRootAsync */ | ||
public static forRootAsync(options: RedisModuleAsyncOptions, connection: string): DynamicModule { | ||
|
||
const redisConnectionProvider: Provider = { | ||
provide: getRedisConnectionToken(connection), | ||
useFactory(options: RedisModuleOptions) { | ||
return createRedisConnection(options) | ||
}, | ||
inject: [getRedisOptionsToken(connection)], | ||
}; | ||
|
||
return { | ||
module: RedisCoreModule, | ||
imports: options.imports, | ||
providers: [...this.createAsyncProviders(options, connection), redisConnectionProvider], | ||
exports: [redisConnectionProvider], | ||
}; | ||
} | ||
|
||
/* createAsyncProviders */ | ||
public static createAsyncProviders(options: RedisModuleAsyncOptions, connection?: string): Provider[] { | ||
|
||
if(!(options.useExisting || options.useFactory || options.useClass)) { | ||
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting'); | ||
} | ||
|
||
if (options.useExisting || options.useFactory) { | ||
return [ | ||
this.createAsyncOptionsProvider(options, connection) | ||
]; | ||
} | ||
|
||
return [ | ||
this.createAsyncOptionsProvider(options, connection), | ||
{ provide: options.useClass, useClass: options.useClass }, | ||
]; | ||
} | ||
|
||
/* createAsyncOptionsProvider */ | ||
public static createAsyncOptionsProvider(options: RedisModuleAsyncOptions, connection?: string): Provider { | ||
|
||
if(!(options.useExisting || options.useFactory || options.useClass)) { | ||
throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting'); | ||
} | ||
|
||
if (options.useFactory) { | ||
return { | ||
provide: getRedisOptionsToken(connection), | ||
useFactory: options.useFactory, | ||
inject: options.inject || [], | ||
}; | ||
} | ||
|
||
return { | ||
provide: getRedisOptionsToken(connection), | ||
async useFactory(optionsFactory: RedisModuleOptionsFactory): Promise<RedisModuleOptions> { | ||
return await optionsFactory.createRedisModuleOptions(); | ||
}, | ||
inject: [options.useClass || options.useExisting], | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { getRedisConnectionToken } from './redis.utils'; | ||
|
||
export const InjectRedis = (connection?: string) => { | ||
return Inject(getRedisConnectionToken(connection)); | ||
}; |
Oops, something went wrong.