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

@ladjs/redis

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ladjs/redis - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

16

index.js

@@ -17,7 +17,7 @@ const IORedis = require('ioredis');

);
client.on('error', err => logger.error(err, getMeta(client)));
client.on('error', (err) => logger.error(err, getMeta(client)));
client.on('close', () =>
logger.debug('redis connection closed', getMeta(client))
);
client.on('reconnecting', time =>
client.on('reconnecting', (time) =>
logger.debug('redis reconnecting', { time, ...getMeta(client) })

@@ -39,12 +39,4 @@ );

// eslint-disable-next-line max-params
function Redis(
config = {},
logger = console,
monitor = false,
maxListeners = 15,
_bindEvents = false
) {
function Redis(config = {}, logger = console, monitor = false) {
const client = new IORedis(config);
client.setMaxListeners(maxListeners);
// https://github.com/luin/ioredis#monitor

@@ -72,3 +64,3 @@ if (monitor) {

if (_bindEvents) bindEvents(client, logger);
bindEvents(client, logger);
return client;

@@ -75,0 +67,0 @@ }

{
"name": "@ladjs/redis",
"description": "Redis for Lad",
"version": "1.0.5",
"version": "1.0.6",
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",

@@ -26,8 +26,9 @@ "ava": {

"devDependencies": {
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"ava": "^3.10.0",
"codecov": "^3.7.0",
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"ava": "^3.10.1",
"codecov": "^3.7.1",
"cross-env": "^7.0.2",
"eslint": "6.x",
"delay": "^4.4.0",
"eslint": "7.5.0",
"eslint-config-xo-lass": "^1.0.3",

@@ -39,5 +40,6 @@ "eslint-plugin-node": "^11.1.0",

"nyc": "^15.1.0",
"remark-cli": "^8.0.0",
"remark-cli": "^8.0.1",
"remark-preset-github": "^2.0.2",
"xo": "0.25"
"sinon": "^9.0.2",
"xo": "^0.32.1"
},

@@ -90,2 +92,16 @@ "engines": {

"license": "MIT",
"lint-staged": {
"*.js": [
"xo --fix",
"git add"
],
"*.md": [
"remark . -qfo",
"git add"
],
"package.json": [
"fixpack",
"git add"
]
},
"main": "index.js",

@@ -92,0 +108,0 @@ "prettier": {

const test = require('ava');
const delay = require('delay');
const sinon = require('sinon');
test.todo('write tests');
const IORedis = require('ioredis');
const Redis = require('..');
test.beforeEach((t) => {
t.context.logger = {
debug: () => {},
error: () => {}
};
});
test('creates Redis', (t) => {
const redis = new Redis();
t.is(typeof redis, 'object');
});
test('creates Redis with logger', async (t) => {
t.plan(10);
const { logger } = t.context;
logger.debug = (message) => {
switch (message) {
case 'redis connection established':
t.true(true);
break;
case 'redis connection ready':
t.true(true);
break;
case 'redis connection closed':
t.true(true);
break;
case 'redis reconnecting':
t.true(true);
break;
case 'redis connection ended':
t.true(true);
break;
case 'redis node connected':
t.true(true);
break;
case 'redis node disconnected':
t.true(true);
break;
default:
}
};
logger.error = (message) => {
switch (message) {
case 'node error':
t.true(true);
break;
case 'error':
t.true(true);
break;
default:
}
};
const redis = await new Redis({}, logger);
t.is(typeof redis, 'object');
redis.monitor();
await delay(1000);
redis.emit('reconnecting');
redis.emit('+node');
redis.emit('-node');
redis.emit('node error', 'node error');
redis.emit('error', 'error');
redis.disconnect();
await delay(1000);
});
test('creates Redis with monitor', async (t) => {
t.plan(13);
const { logger } = t.context;
logger.debug = (message) => {
// console.debug(message);
switch (message) {
case 'redis monitor instance created':
t.true(true);
break;
case 'redis monitor':
t.true(true);
break;
case 'redis connection established':
t.true(true);
break;
case 'redis connection ready':
t.true(true);
break;
case 'redis connection closed':
t.true(true);
break;
case 'redis reconnecting':
t.true(true);
break;
case 'redis connection ended':
t.true(true);
break;
case 'redis node connected':
t.true(true);
break;
case 'redis node disconnected':
t.true(true);
break;
default:
}
};
logger.error = (message) => {
// console.error(message);
switch (message) {
case 'node error':
t.true(true);
break;
case 'error':
t.true(true);
break;
default:
}
};
const redis = await new Redis({}, logger, true);
t.is(typeof redis, 'object');
await delay(1000);
t.is(redis._monitor.status, 'monitoring');
redis.emit('reconnecting');
redis.emit('+node');
redis.emit('-node');
redis.emit('node error', 'node error');
redis.emit('error', 'error');
redis._monitor.emit('monitor');
redis.disconnect();
await delay(1000);
});
test('getMeta > empty status', (t) => {
t.plan(1);
const { logger } = t.context;
logger.debug = (...args) => {
// console.debug(args);
if (args[1].status === '[empty]') t.true(true);
};
const redis = new Redis({}, logger);
redis.setStatus(undefined);
redis.emit('connect');
});
test.serial('errors when creating monitor', (t) => {
t.plan(1);
const { logger } = t.context;
logger.error = (message) => {
if (message === 'error') t.true(true);
};
const monitor = sinon.stub(IORedis.prototype, 'monitor').returns(() => {});
monitor.yields('error', null);
// eslint-disable-next-line no-unused-vars
const redis = new Redis({}, logger, true);
sinon.assert.called(monitor);
sinon.restore();
});

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