Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
skunight committed Dec 5, 2018
0 parents commit b7ee202
Show file tree
Hide file tree
Showing 20 changed files with 699 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# upload
uploads/

.DS_Store
.gulp-cache
src/test
.vscode
dist/
logs/
*.thrift
*.sql
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Nest Redis Module
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dist'
3 changes: 3 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './redis.service'
export * from './redis.module'
export * from './redis.interface'
11 changes: 11 additions & 0 deletions lib/redis-client.provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Redis from "ioredis"
import { REDIS_CLIENT, REDIS_MODULE_OPTIONS } from './redis.constants';
import { RedisModuleOptions } from "./redis.interface";

export const createClient = () => ({
provide: REDIS_CLIENT,
useFactory:(options: RedisModuleOptions) => {
return new Redis(options)
},
inject:[REDIS_MODULE_OPTIONS]
})
2 changes: 2 additions & 0 deletions lib/redis.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const REDIS_MODULE_OPTIONS = Symbol('REDIS_MODULE_OPTIONS')
export const REDIS_CLIENT = Symbol('REDIS_CLIENT')
3 changes: 3 additions & 0 deletions lib/redis.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RedisOptions } from 'ioredis'

export interface RedisModuleOptions extends RedisOptions {}
19 changes: 19 additions & 0 deletions lib/redis.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DynamicModule, Module } from '@nestjs/common';
import { RedisModuleOptions } from './redis.interface';
import { REDIS_MODULE_OPTIONS } from './redis.constants';
import { RedisService } from './redis.service';

@Module({
providers:[RedisService],
exports:[RedisService]
})
export class RedisModule {
static register(options:RedisModuleOptions): DynamicModule {
return {
module: RedisModule,
providers: [
{ provide: REDIS_MODULE_OPTIONS,useValue:options}
]
}
}
}
14 changes: 14 additions & 0 deletions lib/redis.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable, Inject } from "@nestjs/common";
import { REDIS_CLIENT } from './redis.constants';
import * as Redis from "ioredis";

@Injectable()
export class RedisService {
constructor(
@Inject(REDIS_CLIENT) private readonly client: Redis.Redis
) {}

getClient() : Redis.Redis {
return this.client
}
}
5 changes: 5 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"language": "ts",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
6 changes: 6 additions & 0 deletions nodemon-debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --inspect-brk -r ts-node/register src/main.ts"
}
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nestjs-redis",
"version": "0.0.0",
"description": "a nestjs redis module",
"author": "zzy",
"license": "MIT",
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.json",
"precommit": "lint-staged",
"prepublish:npm": "yarn run build",
"publish:npm": "yarn publish --access public"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"ioredis": "^4.2.0",
"rxjs": "^6.2.2"
},
"devDependencies": {
"@types/node": "^10.7.1",
"typescript": "^2.4.2",
"@types/ioredis": "^4.0.4"
}
}
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": false,
"outDir": "./dist",
"rootDir": "./lib",
"skipLibCheck": true
},
"include": [
"lib/**/*",
"../index.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
7 changes: 7 additions & 0 deletions tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "tsconfig.json",
"compilerOptions": {
"types": ["jest", "node"]
},
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
55 changes: 55 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"eofline": false,
"quotemark": [
true,
"single"
],
"indent": false,
"member-access": [
false
],
"ordered-imports": [
false
],
"max-line-length": [
true,
150
],
"member-ordering": [
false
],
"curly": false,
"interface-name": [
false
],
"array-type": [
false
],
"no-empty-interface": false,
"no-empty": false,
"arrow-parens": false,
"object-literal-sort-keys": false,
"no-unused-expression": false,
"max-classes-per-file": [
false
],
"variable-name": [
false
],
"one-line": [
false
],
"one-variable-per-declaration": [
false
]
},
"rulesDirectory": []
}
34 changes: 34 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
entry: ['webpack/hot/poll?1000', './src/main.hmr.ts'],
watch: true,
target: 'node',
externals: [
nodeExternals({
whitelist: ['webpack/hot/poll?1000'],
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
mode: "development",
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'server.js',
},
};
Loading

0 comments on commit b7ee202

Please sign in to comment.