@tgsnake/redis-session
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

tgsnake redis session.

This framework is Redis Session, it possible to make login session with redis for user.

This framework required @tgsnake/core.

Example use.

import { RedisSession } from '@tgsnake/redis-session';
import { Client } from '@tgsnake/core';
const client = new Client(new RedisSession('session name'), apiHash, apiId);
client.addHandler((update) => {
  console.log(update);
});
client.start({
  botToken: '', // got it from bot father.
});

Move from another session instance.

In this example, we will move from StringSession instance.

import { Storages } from '@tgsnake/core';
import { RedisSession } from '@tgsnake/redis-session';
const session = new StringSession('valid string session');
session.move(new RedisSession('session name'));

Redis Options.

Fill the 2nd arguments of constructor RedisSession with JSON object.

interface RedisOptions {
  /**
   * How long should we keep peers in the cache. (in seconds)
   */
  peerExp?: number;
  /**
   * How long should we keep the login information in the cache. (in seconds)
   */
  sessionExp?: number;
  /**
   * separator between session name and session property. (default is ":").
   */
  sessionDelim?: string;
  /**
   * Connect to redis using url. (default is localhost).
   */
  redisUrl?: string;
  /**
   * When redis got error, this function will be called.
   */
  redisError?: { (error: any): any };interface RedisOptions {
  /**
   * How long should we keep peers in the cache. (in seconds)
   */
  peerExp?: number;
  /**
   * How long should we keep the login information in the cache. (in seconds)
   */
  sessionExp?: number;
  /**
   * separator between session name and session property. (default is ":").
   */
  sessionDelim?: string;
  /**
   * Connect to redis using url. (default is localhost).
   */
  redisUrl?: string;
  /**
   * When redis got error, this function will be called.
   */
  redisError?: { (error: any): any };
}```}

Example:

new RedisSession('session name', {
  redisUrl: 'redis://',
});

For more questions, ask on telegram group (@tgsnake) or open github issue.

MIT LICENSE

Readme

Keywords

Package Sidebar

Install

npm i @tgsnake/redis-session

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

25.5 kB

Total Files

11

Last publish

Collaborators

  • butthx