nodecaf-redis
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -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 |
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; | ||
} |
{ | ||
"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; | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10072
85