Comparing version 0.0.2 to 1.0.0
@@ -24,3 +24,3 @@ 'use strict'; | ||
client = new Redis.Cluster(config); | ||
client = new Redis.Cluster(config.nodes, config); | ||
client.on('connect', function() { | ||
@@ -27,0 +27,0 @@ app.coreLogger.info('[egg-redis] cluster connect success'); |
{ | ||
"name": "egg-redis", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "Redis plugin for egg", | ||
@@ -20,3 +20,3 @@ "eggPlugin": { | ||
"autod": "^2.7.1", | ||
"egg": "^0.9.0", | ||
"egg": "^0.12.0", | ||
"egg-bin": "^2.0.2", | ||
@@ -23,0 +23,0 @@ "egg-mock": "^2.3.1", |
@@ -25,4 +25,2 @@ # egg-redis | ||
# This project is still working in progress | ||
## Install | ||
@@ -51,2 +49,42 @@ | ||
## Usage | ||
In controller, you can use `app.redis` to get the redis instance, check [ioredis](https://github.com/luin/ioredis#basic-usage) to see how to use. | ||
```js | ||
// app/controller/home.js | ||
module.exports = app => { | ||
return class HomeController extends app.Controller { | ||
* index() { | ||
const { ctx, app } = this; | ||
// set | ||
yield app.redis.set('foo', 'bar'); | ||
// get | ||
ctx.body = yield app.redis.get('foo'); | ||
} | ||
}; | ||
}; | ||
``` | ||
### Multi Clients | ||
If your Configure with multi clients, you can use `app.redis.get(instanceName)` to get the specific redis instance and use it like above. | ||
```js | ||
// app/controller/home.js | ||
module.exports = app => { | ||
return class HomeController extends app.Controller { | ||
* index() { | ||
const { ctx, app } = this; | ||
// set | ||
yield app.redis.get('instance1').set('foo', 'bar'); | ||
// get | ||
ctx.body = yield app.redis..get('instance1').get('foo'); | ||
} | ||
}; | ||
}; | ||
``` | ||
## Questions & Suggestions | ||
@@ -53,0 +91,0 @@ |
'use strict'; | ||
module.exports = function* () { | ||
const a = yield this.redis.get(a); | ||
this.body = { | ||
status: 'success', | ||
a, | ||
module.exports = app => { | ||
return class HomeController extends app.Controller { | ||
* index() { | ||
const { ctx, app } = this; | ||
yield app.redis.set('foo', 'bar'); | ||
ctx.body = yield app.redis.get('foo'); | ||
} | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function(app) { | ||
app.get('/', app.controller.home); | ||
app.get('/', 'home.index'); | ||
}; |
@@ -12,1 +12,3 @@ 'use strict'; | ||
}; | ||
exports.keys = 'keys'; |
'use strict'; | ||
module.exports = function* () { | ||
const a = yield this.redis.get(a); | ||
this.body = { | ||
status: 'success', | ||
a, | ||
module.exports = app => { | ||
return class HomeController extends app.Controller { | ||
* index() { | ||
const { ctx, app } = this; | ||
yield app.redis.set('foo', 'bar'); | ||
ctx.body = yield app.redis.get('foo'); | ||
} | ||
}; | ||
}; |
'use strict'; | ||
module.exports = function(app) { | ||
app.get('/', app.controller.home); | ||
app.get('/', 'home.index'); | ||
}; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
host: '127.0.0.1', | ||
port: 6379, | ||
port: 7000, | ||
password: '', | ||
@@ -14,3 +14,3 @@ db: '0', | ||
host: '127.0.0.1', | ||
port: 6380, | ||
port: 7001, | ||
password: '', | ||
@@ -22,1 +22,3 @@ db: '0', | ||
}; | ||
exports.keys = 'keys'; |
'use strict'; | ||
const assert = require('assert'); | ||
const mm = require('egg-mock'); | ||
const request = require('supertest'); | ||
describe('test/redis.test.js', () => { | ||
let app, | ||
app2; | ||
before(function* () { | ||
app = mm.app({ | ||
baseDir: 'apps/redisapp', | ||
describe('single client', () => { | ||
let app; | ||
before(function* () { | ||
app = mm.app({ | ||
baseDir: 'apps/redisapp', | ||
}); | ||
yield app.ready(); | ||
}); | ||
app2 = mm.app({ | ||
baseDir: 'apps/redisclusterapp', | ||
}); | ||
yield app2.ready(); | ||
}); | ||
after(() => app.close()); | ||
afterEach(mm.restore); | ||
after(() => { | ||
app.close(); | ||
app2.close(); | ||
}); | ||
afterEach(mm.restore); | ||
it('should query', done => { | ||
app.redis.set('foo', 'bar'); | ||
app.redis.get('foo', function(err, result) { | ||
assert(result === 'bar'); | ||
done(); | ||
it('should query', () => { | ||
return request(app.callback()) | ||
.get('/') | ||
.expect(200) | ||
.expect('bar'); | ||
}); | ||
}); | ||
it('should support cluster config', done => { | ||
app2.redis.set('foo', 'bar'); | ||
app2.redis.get('foo', function(err, result) { | ||
assert(result === 'bar'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
95
11202
23
202