catbox-redis
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -26,3 +26,3 @@ | ||
this.settings = Object.assign({}, internals.defaults, options); | ||
this.client = options.client || null; | ||
this.client = null; | ||
return this; | ||
@@ -35,9 +35,13 @@ }; | ||
if (this.settings.client) { | ||
this.client = this.settings.client; | ||
} | ||
if (this.client) { | ||
return Promise.resolve(); | ||
} | ||
// Return a promise that is resolved when everything is ready | ||
return new Promise((resolve, reject) => { | ||
if (this.client) { | ||
return resolve(); | ||
} | ||
let client; | ||
@@ -84,7 +88,11 @@ | ||
internals.Connection.prototype.stop = function () { | ||
internals.Connection.prototype.stop = async function () { | ||
if (this.client) { | ||
this.client.removeAllListeners(); | ||
this.client.quit(); | ||
try { | ||
if (this.client && !this.settings.client) { | ||
this.client.removeAllListeners(); | ||
await this.client.quit(); | ||
} | ||
} | ||
finally { | ||
this.client = null; | ||
@@ -91,0 +99,0 @@ } |
{ | ||
"name": "catbox-redis", | ||
"description": "Redis adapter for catbox", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"author": "Eran Hammer <eran@hammer.io> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -64,3 +64,3 @@ | ||
expect(client.isReady()).to.equal(true); | ||
client.stop(); | ||
await client.stop(); | ||
expect(client.isReady()).to.equal(false); | ||
@@ -103,2 +103,23 @@ }); | ||
it('does not stop provided client in options', async () => { | ||
const redisClient = RedisClient.createClient(); | ||
await new Promise((resolve, reject) => { | ||
redisClient.once('error', reject); | ||
redisClient.once('ready', resolve); | ||
}); | ||
const client = new Catbox.Client(Redis, { | ||
client: redisClient | ||
}); | ||
await client.start(); | ||
expect(client.isReady()).to.equal(true); | ||
await client.stop(); | ||
expect(client.isReady()).to.equal(false); | ||
expect(redisClient.status).to.equal('ready'); | ||
await redisClient.quit(); | ||
}); | ||
it('gets an item after setting it', async () => { | ||
@@ -251,3 +272,3 @@ | ||
const client = new Catbox.Client(Redis); | ||
client.stop(); | ||
await client.stop(); | ||
@@ -264,3 +285,3 @@ const key = { id: 'x', segment: 'test' }; | ||
const client = new Catbox.Client(Redis); | ||
client.stop(); | ||
await client.stop(); | ||
@@ -277,3 +298,3 @@ const key = { id: 'x', segment: 'test' }; | ||
const client = new Catbox.Client(Redis); | ||
client.stop(); | ||
await client.stop(); | ||
@@ -316,3 +337,3 @@ const key = { id: 'x', segment: 'test' }; | ||
const client = new Catbox.Client(Redis); | ||
client.stop(); | ||
await client.stop(); | ||
@@ -551,3 +572,3 @@ await expect((() => { | ||
expect(redis.isReady()).to.equal(true); | ||
redis.stop(); | ||
await redis.stop(); | ||
}); | ||
@@ -567,3 +588,3 @@ | ||
expect(redis.isReady()).to.equal(true); | ||
redis.stop(); | ||
await redis.stop(); | ||
expect(redis.isReady()).to.equal(false); | ||
@@ -900,3 +921,3 @@ }); | ||
expect(redis.client).to.exist(); | ||
redis.stop(); | ||
await redis.stop(); | ||
expect(redis.client).to.not.exist(); | ||
@@ -903,0 +924,0 @@ }); |
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
34279
840