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.3 to 0.0.4

12

CHANGELOG.md

@@ -8,2 +8,13 @@ # Nodecaf Redis Changelog

## [v0.0.4] - 2021-09-11
### Added
- support for array of channels on subscribe client
### Fixed
- init process not waiting for subscribes to happen
### Changed
- clients to crash on unexpected connection close
## [v0.0.3] - 2021-07-14

@@ -25,1 +36,2 @@

[v0.0.3]: https://gitlab.com/nodecaf/redis/-/tags/v0.0.3
[v0.0.4]: https://gitlab.com/nodecaf/redis/-/tags/v0.0.4

14

lib/main.js
const redis = require('async-redis');
function crash(){
this.emit('error', new Error('Redis connection aborted'));
}
function initClient(client){

@@ -14,2 +18,3 @@ return new Promise( (done, fail) => {

client.off('end', end);
client.on('end', crash);
done();

@@ -32,2 +37,4 @@ });

if(subChannel && onMessage){
subChannel = Array.isArray(subChannel) ? subChannel : [ subChannel ];
subClient = redis.createClient(conf);

@@ -41,2 +48,4 @@ promises.push(initClient(subClient));

client.close = async () => {
client.off('end', crash);
subClient && subClient.off('end', crash);
subClient && await new Promise(done => subClient.quit(done));

@@ -46,7 +55,8 @@ await new Promise(done => client.quit(done));

subChannel && onMessage && subChannel.forEach(chan =>
promises.push(subClient.subscribe(chan)));
await Promise.all(promises);
subChannel && onMessage && subClient.subscribe(subChannel);
return client;
}

2

package.json
{
"name": "nodecaf-redis",
"version": "0.0.3",
"version": "0.0.4",
"description": "A conveninent interface around node redis to work within a nodecaf app.",

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

@@ -18,10 +18,32 @@ const assert = require('assert');

(async function(){
let myr = await redis({ host: REDIS_HOST, port: '6379' }, 'foo-chan', async function(){
const myr = await redis({ host: REDIS_HOST, port: '6379' }, 'foo-chan', async function(){
await myr.close();
done();
});
setTimeout(() => myr.publish('foo-chan', 'here'), 1000);
myr.publish('foo-chan', 'here');
})();
});
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 myr = await redis({ host: REDIS_HOST, port: '6379' });
const p = new Promise(done => myr.on('error', done));
myr.quit();
await p;
});
});
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