Skip to content

sessionRedis Plugin: redis store for egg session

License

Notifications You must be signed in to change notification settings

eggjs/session-redis

Repository files navigation

@eggjs/session-redis

NPM version Node.js CI Test coverage Known Vulnerabilities npm download Node.js Version PRs Welcome CodeRabbit Pull Request Reviews

A session extension for store session in redis.

Install

npm i @eggjs/session-redis @eggjs/redis

Usage

This module dependent on @eggjs/redis plugin, so we must enable both.

// {app_root}/config/plugin.js
exports.sessionRedis = {
  enable: true,
  package: '@eggjs/session-redis',
};

exports.redis = {
  enable: true,
  package: '@eggjs/redis',
};

Configuration

If we only have one redis instance:

// {app_root}/config/config.default.js
exports.redis = {
  client: {
    host: 'your redis host',
    port: 'your redis port',
    password: '',
    db: '0',
  },
  agent:true
};
// no need to set any sessionRedis config

If we have more than one redis instance, we need to configure which instance to be used as session store.

// {app_root}/config/config.default.js

exports.redis = {
  clients: {
    session: { /* config */ },
    cache: { /* config */ },
  },
};

exports.sessionRedis = {
  name: 'session', // specific instance `session` as the session store
};

Questions & Suggestions

Please open an issue here.

License

MIT

Contributors

Contributors

Made with contributors-img.