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

redisess

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redisess

Powerful redis session manager for NodeJS

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33
decreased by-8.33%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version NPM Downloads Build Status Test Coverage

Dependencies DevDependencies Package Quality

Redisess

Redis session manager for NodeJS

Installation

$ npm install redisess --save

Basic Usage

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

const express = require("express");
const Redis = require("ioredis");
const {SessionManager} = require("redisess");
const redis = new Redis(); 

const manager = new SessionManager(redis, {
    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()
prototype.getAllSessions()
prototype.getAllUsers()
prototype.getUserSessions()
prototype.getOldestUserSession()
prototype.exists()
prototype.kill()
prototype.killUser()
prototype.killAll()
prototype.now()
prototype.quit()

Session

prototype.sessionId
prototype.userId
prototype.ttl
prototype.lastAccess
prototype.expires
prototype.expiresIn
prototype.valid
prototype.idle
prototype.[additionalField]
prototype.read()
prototype.get()
prototype.set()
prototype.kill()
prototype.write()
prototype.write()

Node Compatibility

  • node >= 8.x

Change log

To see changelog click here

License

Available under MIT license.

Keywords

FAQs

Package last updated on 18 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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