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

redisess

v2.6.0

Published

Powerful redis session manager for NodeJS

Downloads

90

Readme

NPM Version NPM Downloads Build Status Test Coverage

Dependencies DevDependencies Package Quality

Redisess

High performant advanced Redis session manager for NodeJS.

Installation

Redisess requires "ioredis" library to work. It has been tested for redis, node-redis and ioredis client libraries.

$ npm install ioredis redisess --save

Basic Usage

The example blow show how can you use Redisess in a simple express applicaiton.

import express from 'express';
import Redis from 'ioredis';
import {SessionManager} from 'redisess';

const client = new Redis(); 

const manager = new SessionManager(client, {
    namespace: 'myapp',
    additionalFields: ['groupId'],
    ttl: 120 // Default Time-To-Live value in seconds: 120 seconds
  });

const app = express();
 
app.get('/login', async function (req, res) {
  const userName = req.query.userName;
  const pass = req.query.password;
  //...Login application logic here
  
  const session = await sm.create(userName, {
      ttl: 240, // You can overwrite ttl value per session
      groupId: 111 // You can store additional values
  }); 
  res.send('Your session id is '+session.sessionId);
});

app.get('/killSession/:sessionid', async function (req, res) {
  await sm.kill(req.params.sessionid); 
  res.send('Session ' + req.params.sessionid + ' is closed');
});

app.get('/killUser/:userId', async function (req, res) {
  await sm.killUser(req.params.userId); 
  res.send('All sessions for user "' + req.params.userId +'" are closed.');
})
 
app.listen(3000);

SessionManager

prototype.count()

Returns the number of sessions within the last n seconds. Get all session count if n is not defined or zero

count(secs: number = 0): Promise<number>

Parameters
  • secs: The elapsed time since the last activity of the session. Returns total count of sessions If not defined or zero
  • Return value : Returns the number of sessions.

prototype.countForUser()

Retrieves session count of single user which were active within the last n seconds.

countForUser(userId: string, secs: number = 0): Promise<number>

Parameters
  • userId: Id of the user
  • secs: The elapsed time since the last activity of the session. Returns total count of sessions If not defined or zero
  • Return value : Returns the number of sessions.

prototype.create()

Creates a new session for the user

create(userId: string, props?: { ttl?: number, [index: string]: any }): Promise<Session>

Parameters
  • userId: Id of the user
  • props: Additional properties
    • ttl: Time-To-Live value in seconds
    • *...: Additional fields
  • Return value : Returns new created session.

prototype.get()

Retrieves session by sessionId

get(sessionId: string, noUpdate: boolean = false): Promise<Session>

Parameters
  • sessionId: Id of the session
  • noUpdate: Update state of the session
  • Return value : Returns new created session.

prototype.getAllSessions()

Retrieves all session ids which were active within the last n seconds.

getAllSessions(secs: number): Promise<string[]>

Parameters
  • secs: The elapsed time since the last activity of the session. Returns total count of sessions If not defined or zero
  • Return value : Returns the string array of all sessions.

prototype.getAllUsers()

Retrieves all user ids which were active within the last n seconds.

getAllUsers(secs: number): Promise<string[]>

Parameters
  • secs: The elapsed time since the last activity of the session. Returns total count of sessions If not defined or zero
  • Return value : Returns the string array of all users.

prototype.getUserSessions()

Retrieves session ids of single user which were active within the last n seconds.

getUserSessions(userId: string, n: number = 0): Promise<string[]>

Parameters
  • userId: Id of the user
  • n: The elapsed time since the last activity of the session.
  • Return value : Returns the string array of all sessions for an user.

prototype.getOldestUserSession()

Retrieves oldest session of user

getOldestUserSession(userId: string, noUpdate: boolean = false): Promise<Session>

Parameters
  • userId: Id of the user
  • noUpdate: Update state of the session
  • Return value : Returns new created session.

prototype.exists()

Returns true if sessionId exists, false otherwise

exists(sessionId: string): Promise<Boolean>

Parameters
  • sessionId: Id of the session
  • Return value : Returns Boolean.

prototype.kill()

Kills single session

kill(sessionId: string): Promise<void>

Parameters
  • sessionId: Id of the session
  • Return value : No return value.

prototype.killUser()

Kills all sessions of user

killUser(userId: string): Promise<void>

Parameters
  • userId: Id of the user
  • Return value : No return value.

prototype.killAll()

Kills all sessions for application

killAll(): Promise<void>

Parameters
  • No parameter value
  • Return value : No return value.

prototype.now()

Retrieves present time.

now(): Promise<number>

Parameters
  • No parameter value
  • Return value : Returns number.

prototype.quit()

Stops wipe timer

quit(): void

Parameters
  • No parameter value
  • Return value : No return value.

Session


prototype.sessionId

Returns session id value

sessionId(): string


prototype.userId

Returns user id value

userId(): string


prototype.ttl

Returns Time-To-Live value

ttl(): number


prototype.lastAccess

Returns the time (unix) of last access

lastAccess(): number


prototype.expires

Returns the time (unix) that session be expired.

expires(): number


prototype.expiresIn

Returns duration that session be expired.

expiresIn(): number


prototype.valid

Returns validation of session and user with last access control.

valid(): boolean


prototype.idle

Returns idle duration in seconds.

idle(): number


prototype.[additionalField]

Returns any additional field value


prototype.read()

Reads session info from redis server

read(): Promise<void>


prototype.get()

Retrieves user data from session.

get(key): Promise<any>

Parameters
  • key: string | Array | Object<String,*>
  • Return value : No return value.

prototype.set()

Stores user data to session

set(key, value): Promise<number>

Parameters
  • key: string | Object
  • value: *
  • Return value : Length of values.

prototype.kill()

Kills the session

kill(): Promise<void>


prototype.write()

Write session to redis server.

write(): Promise<void>


Node Compatibility

  • node >= 8.x

Change log

To see changelog click here

License

Available under MIT license.