hazelcast-store
Advanced tools
Comparing version 0.0.6 to 1.0.3
@@ -40,5 +40,5 @@ 'use strict'; | ||
throw new TypeError('Cannot call HazelcastStore constructor as a function'); | ||
debug = dbg((options.debugPrefix || 'hs') + ':hazelcast-store'); | ||
debug('init!'); | ||
@@ -58,6 +58,6 @@ | ||
options.logErrors = function (err) { | ||
console.error('Warning: hazelcast-store reported a client error: ' + err); | ||
}; | ||
console.error('Warning: hazelcast-store reported a client error: ' + err); | ||
}; | ||
} | ||
} | ||
} | ||
@@ -99,11 +99,11 @@ this.mapName = options.mapName || 'Sessions'; | ||
this.sessionsMap.get(psid).then(function (data) { | ||
debug("Item read. Value for key= " + JSON.stringify(psid) + ": " + JSON.stringify(data)); | ||
return fn(null, data); | ||
}) | ||
.catch(function (err) { | ||
debug("Error getting item - " + JSON.stringify(err)); | ||
return fn(err); | ||
}); | ||
this.sessionsMap.then(map => { | ||
map.get(psid).then(value => { | ||
debug("Item read. Value for key= " + JSON.stringify(psid) + ": " + JSON.stringify(value)); | ||
fn(null, value); | ||
}).catch(error => { | ||
debug("Error getting item - " + JSON.stringify(error)); | ||
fn(error); | ||
}); | ||
}); | ||
}; | ||
@@ -130,3 +130,3 @@ | ||
debug('SET "%s" %s ttl:%s', sid, sess, ttl); | ||
} | ||
} | ||
else { | ||
@@ -136,10 +136,11 @@ debug('SET "%s" %s', sid, sess); | ||
this.sessionsMap.put(psid, sess, ttl).then(function (previousValue) { | ||
debug("Item insert succeeded! key=" + JSON.stringify(sid) + " valye=" + JSON.stringify(sess)); | ||
debug("Previous value: " + JSON.stringify(previousValue)); | ||
fn(null, arguments); | ||
}) | ||
.catch(function(err) { | ||
debug("Item insert failed! key=" + JSON.stringify(sid) + " valye=" + JSON.stringify(sess)); | ||
fn(err); | ||
this.sessionsMap.then(map => { | ||
map.set(psid, sess,ttl).then(value => { | ||
debug("Item insert succeeded! key=" + JSON.stringify(psid) + " value=" + JSON.stringify(sess)); | ||
debug("Previous value: " + JSON.stringify(value)); | ||
fn(null, value); | ||
}).catch(error => { | ||
debug("Error getting item - " + JSON.stringify(error)); | ||
fn(error); | ||
}); | ||
}); | ||
@@ -160,5 +161,10 @@ }; | ||
this.sessionsMap.remove(psid).then(function (value) { | ||
debug("Item removed. sid:" + sid + ". Previous value: ", value); | ||
fn(null, sid); | ||
this.sessionsMap.then(map => { | ||
map.remove(psid).then(value => { | ||
debug("Item removed. sid:" + sid + ". Previous value: ", value); | ||
fn(null, sid); | ||
}).catch(error => { | ||
debug("Error setting item - " + JSON.stringify(error)); | ||
fn(error); | ||
}); | ||
}); | ||
@@ -165,0 +171,0 @@ }; |
{ | ||
"name": "hazelcast-store", | ||
"version": "0.0.6", | ||
"version": "1.0.3", | ||
"description": "Hazelcast implementation of expressjs session store", | ||
@@ -22,4 +22,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"express-session": "^1.9.1", | ||
"hazelcast-client": "^0.4.1", | ||
"express-session": "^1.17.0", | ||
"hazelcast-client": "^3.12.1", | ||
"mocha": "^3.0.2" | ||
@@ -26,0 +26,0 @@ }, |
@@ -7,2 +7,5 @@ [![npm](https://img.shields.io/npm/v/hazelcast-store.svg)](https://npmjs.com/package/hazelcast-store) [![Dependencies](https://img.shields.io/david/jackspaniel/hazelcast-store.svg)](https://david-dm.org/jackspaniel/hazelcast-store) ![Downloads](https://img.shields.io/npm/dm/hazelcast-store.svg) | ||
# Versions | ||
- 1.0.0 - added support for latest hazelcast client (3.12.1) | ||
# Setup | ||
@@ -30,3 +33,3 @@ ```sh | ||
HazelcastClient.newHazelcastClient(clientConfig).then((hzInstance) => { | ||
HazelcastClient.newHazelcastClient(clientConfig).then((hzInstance) => { | ||
hazelcastStore.setClient(hzInstance); | ||
@@ -36,3 +39,2 @@ }); | ||
# Options | ||
@@ -50,3 +52,3 @@ A full initialized Hazelcast Client is required. This client is either passed directly using the `client` property, or it can be added after creating the HazelcastStore using the store.setClient() method (see example above). This method is probably the easiest because the code that creates an instance of the Hazelcast client is asynchronous, and express sessions needs to set early in the app.use() chain. | ||
- If a function, it is called anytime an error occurs (useful for custom logging) | ||
- If `false`, no logging occurs. | ||
- If `false`, no logging occurs. | ||
@@ -53,0 +55,0 @@ # TODO |
@@ -7,7 +7,7 @@ "use strict"; | ||
const clientConfig = new HazelcastConfig.ClientConfig(); | ||
clientConfig.networkConfig.addresses = [{host: '127.0.0.1', port: 5701}]; | ||
clientConfig.networkConfig.addresses.push('127.0.0.1:5701'); | ||
describe("hazelcast-store", function () { | ||
const assert = require("assert"); | ||
const id = new Date().getTime(); | ||
@@ -24,6 +24,6 @@ | ||
}; | ||
const options = { | ||
ttl: 15*60*1000, | ||
debugPrefix: 'oc' | ||
const options = { | ||
ttl: 15*60*1000, | ||
debugPrefix: 'oc' | ||
}; | ||
@@ -34,6 +34,6 @@ | ||
assert(typeof store === "object"); | ||
HazelcastClient | ||
.newHazelcastClient(clientConfig) | ||
.then(function (hzInstance) { | ||
.newHazelcastClient(clientConfig) | ||
.then(function (hzInstance) { | ||
assert(typeof hzInstance === "object"); | ||
@@ -43,5 +43,5 @@ store.setClient(hzInstance); | ||
done(); | ||
}); | ||
} | ||
}); | ||
} | ||
let store; | ||
@@ -51,3 +51,3 @@ before("should prepare default empty store with new client", (done) => { | ||
}); | ||
it("should test the default store", (done) => { | ||
@@ -91,3 +91,3 @@ assert(typeof store.client === "object"); | ||
assert.strictEqual(erro, null); | ||
store.get(id, function (error, session) { | ||
@@ -112,7 +112,7 @@ assert.strictEqual(error, null); | ||
assert.strictEqual(err, null); | ||
store.get(id, (error, session) => { | ||
assert.strictEqual(error, null); | ||
assert.deepEqual(session, testSession); // shoudl still exist | ||
done(); | ||
done(); | ||
}); | ||
@@ -122,3 +122,3 @@ }); | ||
}); | ||
it("should not exist after a 2 second timeout and a ttl of 1 second", (done) => { | ||
@@ -128,3 +128,3 @@ setTimeout(() => { | ||
assert.strictEqual(error, null); | ||
assert.strictEqual(session, null); // session should be gone after | ||
assert.strictEqual(session, null); // session should be gone after | ||
done(); | ||
@@ -134,3 +134,3 @@ }); | ||
}); | ||
}); | ||
@@ -137,0 +137,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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17759
376
1
59