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

nodecaf-redis

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodecaf-redis - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0-rc1

0

CHANGELOG.md

@@ -0,0 +0,0 @@ # Nodecaf Redis Changelog

72

lib/main.js
const redis = require('async-redis');
const { createClient } = require('redis');
function crash(){
this.emit('error', new Error('Redis connection aborted'));
}
function initClient(conf){
const client = createClient({
socket: conf,
...conf,
disableOfflineQueue: true
});
function initClient(client){
return new Promise( (done, fail) => {
const end = err => {
fail(err || new Error('Redis connection aborted'));
};
client.once('error', end);
client.once('end', end);
client.once('ready', () => {
client.off('error', end);
client.off('end', end);
client.on('end', crash);
done();
});
client.on('error', err => {
client.disconnect();
throw err;
});
}
module.exports = async function(conf, subChannel, onMessage){
conf = conf || {};
// return new Proxy(client, {
// get(target, cmd){
// return target[cmd.toUpperCase()];
// }
// });
const promises = [];
return client;
}
conf['retry_strategy'] = () => new Error('Redis connection failed');
module.exports = async function(conf, sub){
const client = redis.createClient(conf);
promises.push(initClient(client));
conf = conf || {};
let subClient;
if(subChannel && onMessage){
subChannel = Array.isArray(subChannel) ? subChannel : [ subChannel ];
const client = initClient(conf);
subClient = redis.createClient(conf);
promises.push(initClient(subClient));
client.close = function(){
return Promise.all([
client.quit(),
client.sub?.quit()
]);
};
client.subClient = subClient;
subClient.on('message', onMessage);
if(sub){
client.sub = initClient(conf);
await client.sub.connect();
}
client.close = async () => {
client.off('end', crash);
subClient && subClient.off('end', crash);
subClient && await new Promise(done => subClient.quit(done));
await new Promise(done => client.quit(done));
};
await client.connect();
subChannel && onMessage && subChannel.forEach(chan =>
promises.push(subClient.subscribe(chan)));
await Promise.all(promises);
return client;
}
{
"name": "nodecaf-redis",
"version": "0.0.4",
"version": "0.1.0-rc1",
"description": "A conveninent interface around node redis to work within a nodecaf app.",

@@ -28,5 +28,4 @@ "main": "lib/main.js",

"dependencies": {
"async-redis": "^1.1.7"
},
"devDependencies": {}
"redis": "^4.0.4"
}
}

@@ -0,0 +0,0 @@ # [Nodecaf Redis Wrapper](https://gitlab.com/nodecaf/redis)

@@ -0,1 +1,3 @@

/* eslint-env mocha */
const assert = require('assert');

@@ -10,3 +12,3 @@

it('Should create a redis client', async function(){
let myr = await redis({ host: REDIS_HOST, port: '6379' });
const myr = await redis({ host: REDIS_HOST, port: '6379' });
await myr.set('abc', '23');

@@ -19,6 +21,7 @@ assert.strictEqual(await myr.get('abc'), '23');

(async function(){
const myr = await redis({ host: REDIS_HOST, port: '6379' }, 'foo-chan', async function(){
const myr = await redis({ host: REDIS_HOST, port: '6379' }, true);
await myr.sub.subscribe('foo-chan', async function(){
await myr.close();
done();
});
})
myr.publish('foo-chan', 'here');

@@ -28,24 +31,22 @@ })();

it('Should support multiple channels to subscribe client', function(done){
let cool = 0;
(async function(){
const myr = await redis({ host: REDIS_HOST, port: '6379' }, [ 'foo', 'bar' ], async function(){
cool++;
if(cool == 2){
await myr.close();
done();
}
});
myr.publish('foo', 'here');
myr.publish('bar', 'here');
})();
});
// it('Should crash on connection aborted', async function(){
// const proxy = require('node-tcp-proxy');
// const newProxy = proxy.createProxy(6000, REDIS_HOST, 6379);
it('Should crash on connection aborted', async function(){
const myr = await redis({ host: REDIS_HOST, port: '6379' });
const p = new Promise(done => myr.on('error', done));
myr.quit();
await p;
});
// const myr = await redis({ host: 'localhost', port: '6000' });
// const p = new Promise(done => myr.on('error', done));
// // await myr.quit();
// await myr.set('a', 1);
// // console.log(await myr.get('a'));
// // newProxy.end();
// newProxy.end();
// await p;
// });
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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