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 🙏

© 2026 – Pkg Stats / Ryan Hefner

redsess

v1.1.0

Published

Yet another redis session thing for node

Downloads

79

Readme

redsess

Yet another redis session thing for node.

This is built on top of jed/cookies. You can optionally pass in a KeyGrip instance, or an array of keys to use to sign cookies.

Breaking Changes in 1.0.0

Sessions are now stored as stringified JSON objects using set and get. This means that all sessions that were created using previous versions of redsess will need to be cleared out/nuked/obliterated. Before upgrading to 1.0.0, let your users know that their sessions will be removed!

Example

var RedSess = require('redsess')
, http = require('http')
, Cookies = require('cookies')
, Keygrip = require('keygrip')
, keys = new Keygrip(['some secret keys here'])

// Create a client with the options that you'd pass to node_redis
RedSess.createClient(redisOptions)

http.createServer(function (req, res) {
  var session = new RedSess(req, res, {
    keys: keys, // if keys are provided, they'll be used
    cookieName: 's',
    expire: expirationInSeconds, // default = 2 weeks
    client: redisClient, // defaults to RedSess.client
    keys: [ "this is a string key" ], // will be made into a keygrip obj
    keys: new KeyGrip(keys), // this way also works
  })

  // you can decorate like this if you chose
  req.session = session
  res.session = session

  // .. and then some time later ..
  req.session.get('auth', function (er, auth) {
    if (!auth) {
      // redirect to login page
    } else {
      // do authorized login things
    }
  })

  // .. on the login page, if there's a post ..
  validateLogin(postedData, function (er, isValid) {
    if (isValid)
      req.session.set('auth', postedData)
  })

  // .. on the logout page ..
  req.session.del('auth', function (er) {
    // user is now logged out
  })
}).listen(1337)

Constructor Options

  • expire {Number} Time in seconds that sessions last Default=2 weeks
  • cookieName {String} Cookie name to use for session id's. Default = 's'
  • keys A Keygrip instance to use to sign the session token cookie. (If an array is passed in, then RedSess will make a KeyGrip obj out of it.)
  • client If you have another redis client you'd like to use, then you can do so.
  • cookies If you already have a Cookies object, you may pass that in. If not specified, then it'll make a new one for you.
  • cookieOptions an object that extends the options object that is passed to cookies.set and cookies.get

Methods

Callbacks are all the standard cb(er, result) style.

Deep objects are supported, but cycles in data objects will cause terrible explosively bad awful undefined behavior, so DON'T DO THAT.

  • RedSess.createClient(opts)

Calls redis.createClient with the supplied options. See node_redis for more details. (opts.host and opts.port are passed to redis.createClient as positional arguments, not on the configuration object.)

If there's an opts.auth member, then it will use that string as a password to redis.

  • session.set(k, v, cb)

Sets a key on the session.

  • session.set(object, cb)

Sets a hash of keys and values on the session.

  • session.get(k, cb)

Fetches the key from the session.

  • session.get(cb)

Fetches all keys from the session. If there is no data in the session, then it'll return null.

  • session.del(k, cb)

Deletes a key from the session.

  • session.del(cb)

Deletes the entire session.