adonis-redis

1.0.1 • Public • Published

AdonisJS Framework

Gitter Trello Version Build Status Coverage Status Downloads License

🙏 This is an official AdonisJs redis provider to make your life easier when working with Redis.

Redis provider makes it easier for you to work with redis and has out of the box support for Pub/Sub.

Installation

npm i --save adonis-redis

Setup

Once you have installed the provider from the npm, make sure to follow the below steps to setup the provider.

bootstrap/app.js
const providers = [
  ...,
  'adonis-redis/providers/RedisFactory',
  'adonis-redis/providers/Redis'
]

Redis Factory is a layer on top of IoRedis and Redis provider is something you are going to make use of. So setup an alias for that.

bootstrap/app.js
const aliases = {
  ...,
  Redis: 'Adonis/Addons/Redis'
}

Now you are free to make use of Redis anywhere in your application. Make sure to check official docs for same Redis Documentation.

Redis Config

You have to save the configuration for redis inside config/redis.js file. You can define multiple connections inside this file and specify the main connection under the connection property.

module.exports = {
  connection: 'redis',
  
  redis: {
    port: 6379,          // Redis port
    host: '127.0.0.1',   // Redis host
    family: 4,           // 4 (IPv4) or 6 (IPv6)
    password: 'auth',
    db: 0
  },
  
  redisAlternate: {
    port: 6380,          // Redis port
    host: '127.0.0.1',   // Redis host
    family: 4,           // 4 (IPv4) or 6 (IPv6)
    password: 'auth',
    db: 0
  }
 
}

Cluster Config

module.exports = {
  connection: 'redis',
 
  redis: {
    clusters: [
      {
        port: 6380,
        host: '127.0.0.1'
      },
      {
        port: 6381,
        host: '127.0.0.1'      
      }
    ],
    redisOptions: {}
  }
}

Package Sidebar

Install

npm i adonis-redis

Weekly Downloads

90

Version

1.0.1

License

MIT

Last publish

Collaborators

  • virk