-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
fee6e12
commit 51b1de3
Showing
10 changed files
with
121 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,27 @@ | ||
declare module 'egg' { | ||
export interface EggAppConfig { | ||
sessionRedis: { | ||
name: string | ||
} | ||
} | ||
|
||
export interface Application { | ||
/** | ||
* @member Application#sessionStore | ||
* @property {Function<string>} get - get redis session store | ||
* @property {Function<string, any, number?>} set - set the redis session store | ||
* @property {Function<string>} destroy - destroy of redis session store | ||
* @example | ||
* ```js | ||
* this.app.sessionStore.set('SESSION_KEY', { a: 1 }, 6000); | ||
* this.app.sessionStore.get('SESSION_KEY'); | ||
* this.app.sessionStore.destroy('SESSION_KEY'); | ||
* ``` | ||
*/ | ||
sessionStore: { | ||
get: (key: string) => Promise<any>; | ||
set: (key: string, value: any, maxAge?: number | string) => Promise<void>; | ||
destroy: (key: string) => Promise<void>; | ||
}; | ||
} | ||
} |
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
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
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 @@ | ||
*.js |
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,34 @@ | ||
import { Controller } from 'egg'; | ||
|
||
// add home controller | ||
declare module 'egg' { | ||
interface IController { | ||
home: HomeController; | ||
} | ||
} | ||
|
||
export default class HomeController extends Controller { | ||
async get () { | ||
this.ctx.body = this.ctx.session; | ||
}; | ||
|
||
async set () { | ||
this.ctx.session = this.ctx.query; | ||
this.ctx.body = this.ctx.session; | ||
}; | ||
|
||
async setKey () { | ||
this.ctx.session.key = this.ctx.query.key; | ||
this.ctx.body = this.ctx.session; | ||
}; | ||
|
||
async remove () { | ||
this.ctx.session = null; | ||
this.ctx.body = this.ctx.session; | ||
}; | ||
|
||
async maxAge () { | ||
this.ctx.session.maxAge = Number(this.ctx.query.maxAge); | ||
this.ctx.body = this.ctx.session; | ||
}; | ||
} |
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,10 @@ | ||
import { Application } from 'egg'; | ||
|
||
export default (app: Application) => { | ||
const controller = app.controller; | ||
app.get('/get', controller.home.get); | ||
app.get('/set', controller.home.set); | ||
app.get('/setKey', controller.home.setKey); | ||
app.get('/remove', controller.home.remove); | ||
app.get('/maxAge', controller.home.maxAge); | ||
} |
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,11 @@ | ||
export default { | ||
keys: 'keys', | ||
redis: { | ||
client: { | ||
host: '127.0.0.1', | ||
port: 6379, | ||
db: '0', | ||
password: '', | ||
}, | ||
} | ||
} |
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,10 @@ | ||
import { EggPlugin } from 'egg'; | ||
|
||
const plugin: EggPlugin = { | ||
redis: { | ||
enable: true, | ||
package: 'egg-redis', | ||
} | ||
}; | ||
|
||
export default plugin; |
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 @@ | ||
{ | ||
"name": "ts", | ||
"version": "1.0.0" | ||
} |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"baseUrl": ".", | ||
"module": "commonjs", | ||
"lib": ["es7"], | ||
"strict": true | ||
}, | ||
"include": [ | ||
"../../../**/*" | ||
] | ||
} |