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 = http = Cookies = Keygrip = keys = 'some secret keys here' // Create a client with the options that you'd pass to node_redisRedSess http
Constructor Options
expire
{Number} Time in seconds that sessions last Default=2 weekscookieName
{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 tocookies.set
andcookies.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.