Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Added support for Redis Cluster #510

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ For example, if you wanted to pass a custom configuration to Redis:
}

```

#### Redis Cluster
To use cluster you must prepare config for redis to looks like above:

``` json

{
"databaseConfig" : {
"redis" : {
"nodes" : [
{
"port": "3001",
"host": "redis.app.dev"
},
{
"port": "3001",
"host": "redis.app.dev"
}
],
"options" : []
}
}
}

```
Options are way to pass any custom configuration that ioRedis can handle. For more look at link below.

*Note: No scheme (http/https etc) should be used for the host address*

*A full list of Redis options can be found [here](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options).*
Expand Down
6 changes: 5 additions & 1 deletion src/database/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export class RedisDatabase implements DatabaseDriver {
* Create a new cache instance.
*/
constructor(private options) {
this._redis = new Redis(options.databaseConfig.redis);
if(options.databaseConfig.redis.nodes && options.databaseConfig.redis.nodes.length != 0) {
this._redis = new Redis.Cluster(options.databaseConfig.redis.nodes, options.databaseConfig.redis.options);
} else {
this._redis = new Redis(options.databaseConfig.redis);
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/subscribers/redis-subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export class RedisSubscriber implements Subscriber {
*/
constructor(private options) {
this._keyPrefix = options.databaseConfig.redis.keyPrefix || '';
this._redis = new Redis(options.databaseConfig.redis);
if(options.databaseConfig.redis.nodes && options.databaseConfig.redis.nodes.length != 0) {
this._redis = new Redis.Cluster(options.databaseConfig.redis.nodes, options.databaseConfig.redis.options);
} else {
this._redis = new Redis(options.databaseConfig.redis);
}
}

/**
Expand Down