Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-sessions

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-sessions - npm Package Compare versions

Comparing version 0.1.12 to 0.1.14

8

_docs/redis_data_structure.md

@@ -27,2 +27,10 @@ # Redis Data Structure

## rs:{app}:us:{id} *SET*
A set that contains all session tokens a unique user id has.
Members will be added on *create* operations and removed on *kill* operations.
**MEMBER** The `{sessionToken}`
## rs:{app}:_users ZSET

@@ -29,0 +37,0 @@

113

index.js

@@ -69,2 +69,3 @@ // Generated by CoffeeScript 1.6.2

mc = this._createMultiStatement(options.app, token, options.id, options.ttl);
mc.push(["sadd", "" + this.redisns + options.app + ":us:" + options.id, token]);
mc.push(["hmset", "" + this.redisns + options.app + ":" + token, "id", options.id, "r", 1, "w", 1, "ip", options.ip, "la", this._now(), "ttl", parseInt(options.ttl)]);

@@ -76,3 +77,3 @@ this.redis.multi(mc).exec(function(err, resp) {

}
if (resp[3] !== "OK") {
if (resp[4] !== "OK") {
cb("Unknow error");

@@ -133,3 +134,3 @@ return;

this.get(options, function(err, resp) {
var mc;
var mc, userid;

@@ -146,3 +147,4 @@ if (err) {

}
mc = [["zrem", "" + _this.redisns + options.app + ":_sessions", "" + options.token + ":" + resp.id], ["zrem", "" + _this.redisns + options.app + ":_users", resp.id], ["zrem", "" + _this.redisns + "SESSIONS", "" + options.app + ":" + options.token + ":" + resp.id], ["del", "" + _this.redisns + options.app + ":" + options.token]];
userid = resp.id;
mc = [["zrem", "" + _this.redisns + options.app + ":_sessions", "" + options.token + ":" + userid], ["srem", "" + _this.redisns + options.app + ":us:" + userid, options.token], ["zrem", "" + _this.redisns + "SESSIONS", "" + options.app + ":" + options.token + ":" + userid], ["del", "" + _this.redisns + options.app + ":" + options.token], ["exists", "" + _this.redisns + options.app + ":us:" + userid]];
_this.redis.multi(mc).exec(function(err, resp) {

@@ -153,9 +155,15 @@ if (err) {

}
if (resp[0] === 1 && resp[1] === 1 && resp[2] === 1) {
cb(null, {
kill: 1
if (resp[4] === 0) {
_this.redis.zrem("" + _this.redisns + options.app + ":_users", userid, function() {
if (err) {
cb(err);
return;
}
cb(null, {
kill: resp[3]
});
});
} else {
cb(null, {
kill: 0
kill: resp[3]
});

@@ -178,3 +186,3 @@ }

this.redis.zrange(appsessionkey, 0, -1, function(err, resp) {
var e, globalkeys, mc, thekey, tokenkeys, userkeys, _i, _len;
var e, globalkeys, mc, thekey, tokenkeys, userkeys, ussets, _i, _len;

@@ -186,3 +194,5 @@ if (err) {

if (!resp.length) {
cb(null, 0);
cb(null, {
kill: 0
});
return;

@@ -200,4 +210,19 @@ }

}
mc = [["zrem", appsessionkey].concat(resp), ["zrem", appuserkey].concat(_.uniq(userkeys)), ["zrem", "" + _this.redisns + "SESSIONS"].concat(globalkeys), ["del"].concat(tokenkeys)];
userkeys = _.uniq(userkeys);
ussets = (function() {
var _j, _len1, _results;
_results = [];
for (_j = 0, _len1 = userkeys.length; _j < _len1; _j++) {
e = userkeys[_j];
_results.push("" + this.redisns + options.app + ":us:" + e);
}
return _results;
}).call(_this);
mc = [["zrem", appsessionkey].concat(resp), ["zrem", appuserkey].concat(userkeys), ["zrem", "" + _this.redisns + "SESSIONS"].concat(globalkeys), ["del"].concat(ussets), ["del"].concat(tokenkeys)];
_this.redis.multi(mc).exec(function(err, resp) {
if (err) {
cb(err);
return;
}
cb(null, {

@@ -217,4 +242,4 @@ kill: resp[0]

}
this.redis.zrevrange("" + this.redisns + options.app + ":_sessions", 0, -1, function(err, resp) {
var e, mc, token, _i, _len;
this.redis.smembers("" + this.redisns + options.app + ":us:" + options.id, function(err, resp) {
var mc, token, _i, _len;

@@ -233,19 +258,11 @@ if (err) {

for (_i = 0, _len = resp.length; _i < _len; _i++) {
e = resp[_i];
if (!(e.split(':')[1] === options.id)) {
continue;
}
token = e.split(':')[0];
token = resp[_i];
mc.push(["zrem", "" + _this.redisns + options.app + ":_sessions", "" + token + ":" + options.id]);
mc.push(["zrem", "" + _this.redisns + options.app + ":_users", options.id]);
mc.push(["srem", "" + _this.redisns + options.app + ":us:" + options.id, token]);
mc.push(["zrem", "" + _this.redisns + "SESSIONS", "" + options.app + ":" + token + ":" + options.id]);
mc.push(["del", "" + _this.redisns + options.app + ":" + token]);
}
if (!mc.length) {
cb(null, {
kill: 0
});
}
mc.push(["exists", "" + _this.redisns + options.app + ":us:" + options.id]);
_this.redis.multi(mc).exec(function(err, resp) {
var total, _j, _len1;
var e, total, _j, _len1, _ref;

@@ -257,9 +274,18 @@ if (err) {

total = 0;
for (_j = 0, _len1 = resp.length; _j < _len1; _j += 4) {
e = resp[_j];
_ref = resp.slice(3);
for (_j = 0, _len1 = _ref.length; _j < _len1; _j += 4) {
e = _ref[_j];
total = total + e;
}
cb(null, {
kill: total
});
if (_.last(resp) === 0) {
_this.redis.zrem("" + _this.redisns + options.app + ":_users", options.id, function() {
return cb(null, {
kill: total
});
});
} else {
cb(null, {
kill: total
});
}
});

@@ -329,4 +355,4 @@ });

}
this.redis.zrevrange("" + this.redisns + options.app + ":_sessions", 0, -1, function(err, resp) {
var e, mc, toget, _i, _len;
this.redis.smembers("" + this.redisns + options.app + ":us:" + options.id, function(err, resp) {
var e, mc;

@@ -343,21 +369,8 @@ if (err) {

}
toget = [];
for (_i = 0, _len = resp.length; _i < _len; _i++) {
e = resp[_i];
if (e.split(':')[1] === options.id) {
toget.push(e.split(':')[0]);
}
}
if (!toget.length) {
cb(null, {
sessions: []
});
return;
}
mc = (function() {
var _j, _len1, _results;
var _i, _len, _results;
_results = [];
for (_j = 0, _len1 = toget.length; _j < _len1; _j++) {
e = toget[_j];
for (_i = 0, _len = resp.length; _i < _len; _i++) {
e = resp[_i];
_results.push(["hmget", "" + this.redisns + options.app + ":" + e, "id", "r", "w", "ttl", "d", "la", "ip"]);

@@ -375,7 +388,7 @@ }

o = (function() {
var _j, _len1, _results;
var _i, _len, _results;
_results = [];
for (_j = 0, _len1 = resp.length; _j < _len1; _j++) {
e = resp[_j];
for (_i = 0, _len = resp.length; _i < _len; _i++) {
e = resp[_i];
_results.push(this._prepareSession(e));

@@ -382,0 +395,0 @@ }

{
"name": "redis-sessions",
"description": "A universal session store for Redis",
"version": "0.1.12",
"version": "0.1.14",
"author": "P. Liess <smrchy+npm@gmail.com>",

@@ -6,0 +6,0 @@ "engines": {

@@ -33,7 +33,7 @@ # Redis Sessions

With Redis being run on the same machine the test script (run via `npm test`) on a 2009 iMac:
With Redis being run on the same machine the test script (run via `npm test`) on a 2011 iMac:
* Creates 1000 sessions in around 240ms.
* Gets those 1000 sessions and validates them in around 260ms.
* Removes those 1000 sessions in 25ms.
* Creates 1000 sessions in around 170ms.
* Gets those 1000 sessions and validates them in around 155ms.
* Removes those 1000 sessions in 18ms.

@@ -40,0 +40,0 @@ ## Useage via REST

@@ -394,3 +394,3 @@ // Generated by CoffeeScript 1.6.2

});
it('Activity for app1 should show 1 user', function(done) {
it('Activity for app1 should show 2 users still', function(done) {
rs.activity({

@@ -403,3 +403,3 @@ app: app1,

resp.should.have.keys('activity');
resp.activity.should.equal(1);
resp.activity.should.equal(2);
done();

@@ -406,0 +406,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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