Socket
Socket
Sign inDemoInstall

egg-redis

Package Overview
Dependencies
10
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 0.0.2

test/fixtures/apps/redisapp/logs/redisapp/common-error.log

18

config/config.default.js

@@ -19,8 +19,10 @@ 'use strict';

// Cluster Redis
// cluster: [{
// host: 'host',
// port: 'port',
// family: 'user',
// password: 'password',
// db: 'db',
// client: [
// cluster: true,
// nodes: {
// host: 'host',
// port: 'port',
// family: 'user',
// password: 'password',
// db: 'db',
// },{

@@ -36,3 +38,3 @@ // host: 'host',

// clients: {
// db1: {
// instance1: {
// host: 'host',

@@ -44,3 +46,3 @@ // port: 'port',

// },
// db2: {
// instance2: {
// host: 'host',

@@ -47,0 +49,0 @@ // port: 'port',

@@ -7,23 +7,47 @@ 'use strict';

module.exports = app => {
app.addSingleton('ioredis', createOneClient);
app.addSingleton('redis', createClient);
};
function createOneClient(config, app) {
assert(config.host && config.port && config.password && config.db,
`[egg-redis] 'host: ${config.host}', 'port: ${config.port}', 'password: ${config.password}', 'db: ${config.db}' are required on config`);
let count = 0;
app.coreLogger.info('[egg-redis] connecting redis://:%s@%s:%s/%s',
config.password, config.host, config.port, config.db);
const client = new Redis(config);
function createClient(config, app) {
let client;
client.on('connect', function () {
if (config.cluster === true) {
assert(config.nodes && config.nodes.length !== 0, '[egg-redis] cluster nodes configuration is required when use cluster redis');
});
config.nodes.forEach(client => {
assert(client.host && client.port && client.password !== undefined && client.db,
`[egg-redis] 'host: ${client.host}', 'port: ${client.port}', 'password: ${client.password}', 'db: ${client.db}' are required on config`);
});
app.coreLogger.info('[egg-redis] cluster connecting start');
client.on('error', function () {
client = new Redis.Cluster(config);
client.on('connect', function() {
app.coreLogger.info('[egg-redis] cluster connect success');
});
client.on('error', function(error) {
app.coreLogger.error(error);
});
} else {
assert(config.host && config.port && config.password !== undefined && config.db,
`[egg-redis] 'host: ${config.host}', 'port: ${config.port}', 'password: ${config.password}', 'db: ${config.db}' are required on config`);
});
app.coreLogger.info('[egg-redis] connecting redis://:%s@%s:%s/%s',
config.password, config.host, config.port, config.db);
client.on('reconnect', function () {
client = new Redis(config);
client.on('connect', function() {
app.coreLogger.info('[egg-redis] connect success on redis://:%s@%s:%s/%s',
config.password, config.host, config.port, config.db);
});
client.on('error', function(error) {
app.coreLogger.error(error);
});
}
app.beforeStart(function* () {
const result = yield client.time();
const index = count++;
app.coreLogger.info(`[egg-redis] instance[${index}] status OK, redis currentTime: ${result[0]}`);
});

@@ -33,29 +57,1 @@

}
function createClusterClient(config, app) {
config.forEach((client) => {
assert(client.host && client.port && client.password && client.db,
`[egg-redis] 'host: ${client.host}', 'port: ${client.port}', 'password: ${client.password}', 'db: ${client.db}' are required on config`);
})
/*
app.coreLogger.info('[egg-redis] connecting %s@%s:%s/%s',
config.user, config.host, config.port, config.database);
*/
const cluster = new Redis.Cluster(config);
cluster.on('connect', function () {
});
cluster.on('error', function () {
});
cluster.on('reconnect', function () {
});
return cluster;
}
{
"name": "egg-redis",
"version": "0.0.1",
"version": "0.0.2",
"description": "Redis plugin for egg",

@@ -16,3 +16,3 @@ "eggPlugin": {

"dependencies": {
"ioredis": "*"
"ioredis": "^2.5.0"
},

@@ -19,0 +19,0 @@ "devDependencies": {

@@ -6,7 +6,7 @@ 'use strict';

host: '127.0.0.1',
port: 3306,
port: 6379,
password: '',
db: 'test',
db: '0',
},
agent:true
};
'use strict';
const assert = require('assert');
const request = require('supertest');
const mm = require('egg-mock');
const utility = require('utility');
const path = require('path');
const fs = require('fs');
describe('test/redis.test.js', () => {
let app;
const uid = utility.randomString();
let app,
app2;
before(() => {
before(function* () {
app = mm.app({
baseDir: 'apps/redisapp',
});
return app.ready();
app2 = mm.app({
baseDir: 'apps/redisclusterapp',
});
yield app2.ready();
});
beforeEach(function* () {
after(() => {
app.close();
app2.close();
});
afterEach(function* () {
afterEach(mm.restore);
it('should query', done => {
app.redis.set('foo', 'bar');
app.redis.get('foo', function(err, result) {
assert(result === 'bar');
done();
});
});
after(done => {
app.redis.end(err => {
app.close();
done(err);
it('should support cluster config', done => {
app2.redis.set('foo', 'bar');
app2.redis.get('foo', function(err, result) {
assert(result === 'bar');
done();
});
});
afterEach(mm.restore);
it('should query', () => {
return request(app.callback())
.get('/')
.expect(200);
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc