Skip to content

Commit 3f05cce

Browse files
committed
feat:first implement
0 parents  commit 3f05cce

22 files changed

+475
-0
lines changed

.autod.conf.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
module.exports = {
4+
write: true,
5+
prefix: '^',
6+
test: [
7+
'test',
8+
'benchmark',
9+
],
10+
devdep: [
11+
'egg',
12+
'egg-bin',
13+
'autod',
14+
'eslint',
15+
'eslint-config-egg',
16+
'supertest',
17+
],
18+
exclude: [
19+
'./test/fixtures',
20+
],
21+
}

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/fixtures
2+
coverage

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "eslint-config-egg"
3+
}

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
Thank you for your pull request. Please review below requirements.
3+
Bug fixes and new features should include tests and possibly benchmarks.
4+
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
5+
6+
感谢您贡献代码。请确认下列 checklist 的完成情况。
7+
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
8+
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
9+
-->
10+
11+
##### Checklist
12+
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
13+
14+
- [ ] `npm test` passes
15+
- [ ] tests and/or benchmarks are included
16+
- [ ] documentation is changed or added
17+
- [ ] commit message follows commit guidelines
18+
19+
##### Affected core subsystem(s)
20+
<!-- Provide affected core subsystem(s). -->
21+
22+
23+
##### Description of change
24+
<!-- Provide a description of the change below this comment. -->

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
logs/
2+
npm-debug.log
3+
node_modules/
4+
coverage/
5+
.idea/
6+
run/
7+
.DS_Store
8+
*.swp
9+

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '6'
5+
- '7'
6+
install:
7+
- npm i npminstall && npminstall
8+
script:
9+
- npm run ci
10+
after_script:
11+
- npminstall codecov && codecov
12+
services:
13+
- mysql

History.md

Whitespace-only changes.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Alibaba Group Holding Limited and other contributors.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# egg-redis
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![build status][travis-image]][travis-url]
5+
[![Test coverage][codecov-image]][codecov-url]
6+
[![David deps][david-image]][david-url]
7+
[![Known Vulnerabilities][snyk-image]][snyk-url]
8+
[![npm download][download-image]][download-url]
9+
10+
[npm-image]: https://img.shields.io/npm/v/egg-redis.svg?style=flat-square
11+
[npm-url]: https://npmjs.org/package/egg-redis
12+
[travis-image]: https://img.shields.io/travis/eggjs/egg-redis.svg?style=flat-square
13+
[travis-url]: https://travis-ci.org/eggjs/egg-redis
14+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-redis.svg?style=flat-square
15+
[codecov-url]: https://codecov.io/github/eggjs/egg-redis?branch=master
16+
[david-image]: https://img.shields.io/david/eggjs/egg-redis.svg?style=flat-square
17+
[david-url]: https://david-dm.org/eggjs/egg-redis
18+
[snyk-image]: https://snyk.io/test/npm/egg-redis/badge.svg?style=flat-square
19+
[snyk-url]: https://snyk.io/test/npm/egg-redis
20+
[download-image]: https://img.shields.io/npm/dm/egg-redis.svg?style=flat-square
21+
[download-url]: https://npmjs.org/package/egg-redis
22+
23+
Redis client(support redis portocal) based on ioredis for egg framework
24+
25+
# This project is still working in progress
26+
27+
## Install
28+
29+
```bash
30+
$ npm i egg-redis --save
31+
```
32+
33+
redis Plugin for egg, support egg application access to redis.
34+
35+
This plugin based on [ioredis](https://github.com/luin/ioredis), if you want to know specific usage, you should refer to the document of [ioredis](https://github.com/luin/ioredis).
36+
37+
## Configuration
38+
39+
Change `${app_root}/config/plugin.js` to enable redis plugin:
40+
41+
```js
42+
exports.redis = {
43+
enable: true,
44+
package: 'egg-redis',
45+
};
46+
```
47+
48+
Configure redis information in `${app_root}/config/config.default.js`:
49+
50+
## Questions & Suggestions
51+
52+
Please open an issue [here](https://github.com/eggjs/egg/issues).
53+
54+
## License
55+
56+
[MIT](LICENSE)

README.zh-CN.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# egg-redis
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![build status][travis-image]][travis-url]
5+
[![Test coverage][codecov-image]][codecov-url]
6+
[![David deps][david-image]][david-url]
7+
[![Known Vulnerabilities][snyk-image]][snyk-url]
8+
[![npm download][download-image]][download-url]
9+
10+
[npm-image]: https://img.shields.io/npm/v/egg-redis.svg?style=flat-square
11+
[npm-url]: https://npmjs.org/package/egg-redis
12+
[travis-image]: https://img.shields.io/travis/eggjs/egg-redis.svg?style=flat-square
13+
[travis-url]: https://travis-ci.org/eggjs/egg-redis
14+
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-redis.svg?style=flat-square
15+
[codecov-url]: https://codecov.io/github/eggjs/egg-redis?branch=master
16+
[david-image]: https://img.shields.io/david/eggjs/egg-redis.svg?style=flat-square
17+
[david-url]: https://david-dm.org/eggjs/egg-redis
18+
[snyk-image]: https://snyk.io/test/npm/egg-redis/badge.svg?style=flat-square
19+
[snyk-url]: https://snyk.io/test/npm/egg-redis
20+
[download-image]: https://img.shields.io/npm/dm/egg-redis.svg?style=flat-square
21+
[download-url]: https://npmjs.org/package/egg-redis
22+
23+
Redis client(support redis portocal) based on ioredis for egg framework
24+
25+
# This project is still working in progress
26+
27+
## Install
28+
29+
```bash
30+
$ npm i egg-redis --save
31+
```
32+
33+
redis Plugin for egg, support egg application access to redis.
34+
35+
This plugin based on [ioredis](https://github.com/luin/ioredis), if you want to know specific usage, you should refer to the document of [ioredis](https://github.com/luin/ioredis).
36+
37+
## Configuration
38+
39+
Change `${app_root}/config/plugin.js` to enable redis plugin:
40+
41+
```js
42+
exports.redis = {
43+
enable: true,
44+
package: 'egg-redis',
45+
};
46+
```
47+
48+
Configure redis information in `${app_root}/config/config.default.js`:
49+
50+
## Questions & Suggestions
51+
52+
Please open an issue [here](https://github.com/eggjs/egg/issues).
53+
54+
## License
55+
56+
[MIT](LICENSE)

agent.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const redis = require('./lib/redis');
4+
5+
module.exports = agent => {
6+
if (agent.config.redis.agent) redis(agent);
7+
};

app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const redis = require('./lib/redis');
4+
5+
module.exports = app => {
6+
if (app.config.redis.app) redis(app);
7+
};

appveyor.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: '6'
4+
- nodejs_version: '7'
5+
6+
install:
7+
- ps: Install-Product node $env:nodejs_version
8+
- npm i npminstall && node_modules\.bin\npminstall
9+
10+
test_script:
11+
- node --version
12+
- npm --version
13+
- npm run ci
14+
15+
build: off

config/config.default.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
exports.redis = {
4+
default: {
5+
},
6+
app: true,
7+
agent: false,
8+
9+
// Single Redis
10+
// client: {
11+
// host: 'host',
12+
// port: 'port',
13+
// family: 'user',
14+
// password: 'password',
15+
// db: 'db',
16+
// },
17+
18+
// Cluster Redis
19+
// cluster: [{
20+
// host: 'host',
21+
// port: 'port',
22+
// family: 'user',
23+
// password: 'password',
24+
// db: 'db',
25+
// },{
26+
// host: 'host',
27+
// port: 'port',
28+
// family: 'user',
29+
// password: 'password',
30+
// db: 'db',
31+
// }],
32+
33+
// Multi Redis
34+
// clients: {
35+
// db1: {
36+
// host: 'host',
37+
// port: 'port',
38+
// family: 'user',
39+
// password: 'password',
40+
// db: 'db',
41+
// },
42+
// db2: {
43+
// host: 'host',
44+
// port: 'port',
45+
// family: 'user',
46+
// password: 'password',
47+
// db: 'db',
48+
// },
49+
// },
50+
};

lib/redis.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const Redis = require('ioredis');
5+
6+
module.exports = app => {
7+
app.addSingleton('ioredis', createOneClient);
8+
};
9+
10+
function createOneClient(config, app) {
11+
assert(config.host && config.port && config.password && config.db,
12+
`[egg-redis] 'host: ${config.host}', 'port: ${config.port}', 'password: ${config.password}', 'db: ${config.db}' are required on config`);
13+
14+
app.coreLogger.info('[egg-redis] connecting redis://:%s@%s:%s/%s',
15+
config.password, config.host, config.port, config.db);
16+
const client = new Redis(config);
17+
18+
client.on('connect', function () {
19+
20+
});
21+
22+
client.on('error', function () {
23+
24+
});
25+
26+
client.on('reconnect', function () {
27+
28+
});
29+
30+
return client;
31+
}
32+
33+
function createClusterClient(config, app) {
34+
35+
config.forEach((client) => {
36+
assert(client.host && client.port && client.password && client.db,
37+
`[egg-redis] 'host: ${client.host}', 'port: ${client.port}', 'password: ${client.password}', 'db: ${client.db}' are required on config`);
38+
})
39+
/*
40+
app.coreLogger.info('[egg-redis] connecting %s@%s:%s/%s',
41+
config.user, config.host, config.port, config.database);
42+
*/
43+
44+
const cluster = new Redis.Cluster(config);
45+
46+
cluster.on('connect', function () {
47+
48+
});
49+
50+
cluster.on('error', function () {
51+
52+
});
53+
54+
cluster.on('reconnect', function () {
55+
56+
});
57+
58+
return cluster;
59+
}

0 commit comments

Comments
 (0)