Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-redis

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-redis - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

2

lib/redis.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc