Skip to content

Commit

Permalink
feat(instructions): implement instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 2, 2017
1 parent 43f2422 commit fa31bbc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 23 deletions.
24 changes: 24 additions & 0 deletions instructions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

/*
* adonis-redis
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const path = require('path')

module.exports = async function (cli) {
try {
await cli.copy(
path.join(__dirname, './examples/redis.js'),
path.join(cli.helpers.configPath(), 'redis.js')
)
cli.command.completed('create', 'config/redis.js')
} catch (error) {
// ignore error when redis.js already exists
}
}
38 changes: 38 additions & 0 deletions instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Registering provider

Make sure you register the provider inside `start/app.js` file before making use redis.

```js
const providers = [
'@adonisjs/redis/providers/RedisProvider'
]
```

Once that done you can make use of Redis anywhere by importing the redis provider.

```js
const Redis = use('Redis')
await Redis.get()
```

## Pub Sub
In order to make use of pub/sub you can create `start/redis.js` file and subscribe to channels.

```js
const Redis = use('Redis')
Redis.subscribe('news', async () => {
})

// or bind listeners from `app/Listeners` directory
Redis.subcribe('news', 'News.onMessage')
```

## Config
The config file `start/redis.js` contains all the configuration. Feel free to tweak it as per your needs.

## Environment variables
The configuration file makes use of **Environment variables**, make sure to define them for development and in production too

```
REDIS_CONNECTION=local
```
22 changes: 0 additions & 22 deletions providers/RedisFactoryProvider.js

This file was deleted.

6 changes: 5 additions & 1 deletion providers/RedisProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const { ServiceProvider } = require('@adonisjs/fold')

class RedisProvider extends ServiceProvider {
register () {
this.app.singleton('Adonis/Addons/Redis', function (app) {
this.app.bind('Adonis/Addons/RedisFactory', () => require('../src/RedisFactory'))

this.app.singleton('Adonis/Addons/Redis', (app) => {
const RedisFactory = app.use('Adonis/Addons/RedisFactory')
const Config = app.use('Adonis/Src/Config')
const Redis = require('../src/Redis')
return new Redis(Config, RedisFactory)
})

this.app.alias('Adonis/Addons/Redis', 'Redis')
}
}

Expand Down

0 comments on commit fa31bbc

Please sign in to comment.