UNPKG

redisess

Version:

Powerful redis session manager for NodeJS

136 lines (135 loc) 3.96 kB
import Redis, { Cluster } from 'ioredis'; import { Session } from './session.js'; export declare namespace SessionManager { interface Options { namespace?: string; ttl?: number; wipeInterval?: number; additionalFields?: string[]; } } export type ResultSession = Session & Record<string, any>; /** * * @class */ export declare class SessionManager { private readonly _backend; private readonly _additionalFields; /** * * @param {Object} client * @param {Object} [props] * @param {Object} [props.namespace='sm'] * @param {number} [props.ttl] Time-To-Live value in seconds * @param {number} [props.wipeInterval=1000] * @param {Array<String>} [props.additionalFields] */ constructor(client: Redis | Cluster, props?: SessionManager.Options); get additionalFields(): string[]; get namespace(): string | undefined; get ttl(): number | undefined; /** * Returns the number of sessions within the last n seconds. * @param {number} [secs] The elapsed time since the last activity of the session. Returns total count of sessions If not defined or zero * @return {Promise<Number>} */ count(secs?: number): Promise<number>; /** * Retrieves session count of single user which were active within the last n seconds. * * @param {string} userId * @param {number} [secs] * @return {Promise<number>} */ countForUser(userId: string, secs?: number): Promise<number>; /** * Creates a new session for the user * * @param {string} userId * @param {Object.<string, *>} [props] * @param {number} [props.ttl] Time-To-Live value in seconds * @param props */ create(userId: string, props?: { ttl?: number; [index: string]: any; }): Promise<ResultSession>; /** * Retrieves session by sessionId * * @param {string} sessionId * @param {boolean} [noUpdate=false] * @return {Promise<ResultSession>} */ get(sessionId: string, noUpdate?: boolean): Promise<ResultSession | undefined>; /** * Retrieves all session ids which were active within the last n seconds. * * @param {number} [secs] * @return {Promise<Array<String>>} */ getAllSessions(secs?: number): Promise<string[]>; /** * Retrieves all user ids which were active within the last n seconds. * * @param {number} [secs] * @return {Promise<Array<String>>} */ getAllUsers(secs?: number): Promise<string[]>; /** * Retrieves session ids of single user which were active within the last n seconds. * * @param {string} userId * @param {number} [n] * @return {Promise<Array<String>>} */ getUserSessions(userId: string, n?: number): Promise<string[]>; /** * Retrieves oldest session of user * * @param {string} userId * @param {boolean} [noUpdate=false] * @return {Promise<ResultSession>} */ getOldestUserSession(userId: string, noUpdate?: boolean): Promise<ResultSession | undefined>; /** * Returns true if sessionId exists, false otherwise, * * @param {string} sessionId * @return {Promise<Boolean>} */ exists(sessionId: string): Promise<Boolean>; /** * Kills single session * * @param {string} sessionId * @return {Promise<void>} */ kill(sessionId: string): Promise<void>; /** * Kills all sessions of user * * @param {string} userId * @return {Promise} */ killUser(userId: string): Promise<void>; /** * Kills all sessions for application * * @return {Promise} */ killAll(): Promise<void>; now(): Promise<number>; /** * Stops wipe timer */ quit(): void; wipe(): Promise<void>; /** * * @return {string} * @private */ private _createSessionId; }