npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-sesh

v1.0.10

Published

A redis based session store which is pretty much as simple as possible. Probably too simple.

Downloads

5

Readme

redis-sesh

Hard to say; easy to use.

redis-sesh is a redis based session store which is pretty much as simple as possible. Probably too simple.

API:

{
   set: function(id, callback){},
   get: function(session, callback){},
   liv: function(session, callback){},
   die: function(session, callback){}
}

To use:

Make sure you have node, npm and redis.

npm install redis-sesh --save --save-exact (You do use --save-exact, right?)

var redis = request("redis"); // don't forget to run: `npm install redis --save --save-exact`
// `createClient` takes some options. Make sure you configure it to actually work for your setup.
var redisClient = redis.createClient();

var RedisSesh = request("redis-sesh");
var ttl = 86400; // The ttl argument is optional. Leave it off (or set to 0) for never-expiring sessions *
var sesh = new RedisSesh(redisClient, "sesh", ttl);

var id = 1337; // this is the thing you want to 
sesh.set(id, function(err, sessionId){
    if(err){/*always make sure you handle your errors, folks*/}
    console.log("Look at my session id: %s!, sessionId);
});

var sessionId = "some session id previously generated by redis-sesh";

// get the "id" for the sessionId
sesh.get(sessionId, function(err, userId){
    if(err){/*...*/}
    console.log("Look at my user id: %s!, userId);
});

// make the session last longer (resets expiration to the ttl value):
sesh.liv(sessionId, function(err){
    if(err){/*...*/}
    console.log("Um, it's done I guess");
});

// This kills the crab, er, session.
sesh.die(sessionId, function(err){
    if(err){/*...*/}
    console.log("The session should be gone now");
});

But are the session ids secure?

It generates 32 bytes of cryptographically random data for the session and converts it to base64. That's 3 nonillion possible combinations, or 3 thousand billion billion billion.

It basically does something like this: crypto.randomBytes(32).toString("base64");. Ok, not basically, that's what it does.

Additionally, redis-sesh checks for session id collisions (via setnx) and recomputes a new session id automatically if a collision is found (there is still a chance a session id could have expired but the user still has it, then redis-sesh creates an idential session id, and the old user then visits again. But there is also a chance that you'll get hit by a duck made of pure gold that has the winning lottery numbers engraved on it's beak, but I digress).

Something to know:

redis-sesh doesn't validate anything you pass to it. It won't (de)serialize anything for you. It won't even check if you supplied a callback function or not.