sessionstore
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -131,5 +131,14 @@ 'use strict'; | ||
} | ||
this.db.save(hash, sess, callback || function() {}); | ||
this.db.save(hash, sess._rev, sess, function(err) { | ||
if (err && err.error === 'conflict' && err.reason.indexOf('update conflict') >= 0) { | ||
return callback(new Error('ConcurrencyError: Session was updated by someone else!')); | ||
} | ||
callback(err); | ||
}); | ||
}, | ||
//touch: function (sid, sess, callback) { | ||
// this.set(sid, sess, callback); | ||
//}, | ||
get: function (hash, callback) { | ||
@@ -136,0 +145,0 @@ var self = this; |
@@ -130,2 +130,5 @@ 'use strict'; | ||
sess._version = sess._version || 1; | ||
sess._version++; | ||
this.client.index({ | ||
@@ -135,7 +138,17 @@ index: this.index, | ||
id: this.options.prefix + sid, | ||
version: sess._version > 2 ? sess._version - 1 : undefined, | ||
ttl: ttl, | ||
body: sess | ||
}, callback || function () {}); | ||
}, function (err, res) { | ||
if (err && (err.message.toLowerCase().indexOf('version') >= 0)) { | ||
return callback(new Error('ConcurrencyError: Session was updated by someone else!')); | ||
} | ||
callback(err, res); | ||
}); | ||
}, | ||
//touch: function (sid, sess, callback) { | ||
// this.set(sid, sess, callback); | ||
//}, | ||
get: function (sid, callback) { | ||
@@ -142,0 +155,0 @@ this.client.get({ |
@@ -81,2 +81,6 @@ 'use strict'; | ||
//touch: function (sid, sess, callback) { | ||
// this.set(sid, sess, callback); | ||
//}, | ||
get: function (sid, callback) { | ||
@@ -83,0 +87,0 @@ var prefixedSid = this.prefix + ':' + sid; |
@@ -140,3 +140,16 @@ 'use strict'; | ||
this.sessions.update({_id: sid}, sess, { upsert: true, safe: true }, function(err) { | ||
var query = { | ||
_id: sid | ||
}; | ||
if (sess._hash) { | ||
query._hash = sess._hash; | ||
} | ||
sess._hash = new ObjectID().toString(); | ||
this.sessions.update(query, sess, { upsert: true, safe: true }, function(err, modifiedCount) { | ||
if (modifiedCount && modifiedCount.result && modifiedCount.result.n === 0) { | ||
return callback(new Error('ConcurrencyError: Session was updated by someone else!')); | ||
} | ||
if (err) { | ||
@@ -150,2 +163,6 @@ if (callback) callback(err); | ||
//touch: function (sid, sess, callback) { | ||
// this.set(sid, sess, callback); | ||
//}, | ||
get: function (sid, callback) { | ||
@@ -152,0 +169,0 @@ this.sessions.findOne({ |
@@ -130,2 +130,16 @@ 'use strict'; | ||
touch: function (sid, sess, callback) { | ||
var prefixedSid = this.prefix + ':' + sid; | ||
var ttl = this.ttl; | ||
if (sess && sess.cookie && sess.cookie.expires) { | ||
var expInMs = (new Date(sess.cookie.expires)).getTime() - Date.now(); | ||
if (expInMs < 1000) { | ||
expInMs = 1000; | ||
} | ||
ttl = Math.round(expInMs / 1000); | ||
} | ||
this.client.expire(prefixedSid, ttl, callback || function () {}); | ||
}, | ||
get: function (sid, callback) { | ||
@@ -132,0 +146,0 @@ var prefixedSid = this.prefix + ':' + sid; |
@@ -96,2 +96,6 @@ 'use strict'; | ||
//touch: function (sid, sess, callback) { | ||
// this.set(sid, sess, callback); | ||
//}, | ||
get: function (sid, callback) { | ||
@@ -98,0 +102,0 @@ this.sessions.findOne({ |
{ | ||
"author": "adrai", | ||
"name": "sessionstore", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"private": false, | ||
@@ -22,4 +22,4 @@ "main": "index.js", | ||
"cradle": ">=0.2.7", | ||
"elasticsearch": "^5.0.0", | ||
"eslint": "^0.24.1", | ||
"elasticsearch": ">=5.0.0", | ||
"eslint": ">=1.0.0", | ||
"expect.js": ">= 0.1.2", | ||
@@ -26,0 +26,0 @@ "express": ">= 2.5.0", |
@@ -0,1 +1,4 @@ | ||
#### v1.2.5 | ||
- redis: implemented touch | ||
#### v1.2.4 | ||
@@ -2,0 +5,0 @@ - optimization for `npm link`'ed development |
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
39223
1027