Skip to content

Commit

Permalink
fix: 🐛 add optional RedisClientOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Jun 6, 2023
1 parent 056274c commit af2fb5f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Client.ts
@@ -1,5 +1,5 @@
import EventEmitter from 'events';
import { createClient } from 'redis';
import { RedisClientOptions, createClient } from 'redis';
import { parseResponse } from './parseResponse';
import { JSONResponse } from './responses';

Expand Down Expand Up @@ -106,10 +106,10 @@ export class Client extends EventEmitter {

private format: `${Format}` = Format.RESP;

constructor(url: string) {
constructor(url: string, options?: RedisClientOptions) {
super();

this.redis = createClient({ url })
this.redis = createClient({ ...options, url })
.on('ready', () => {
this.format = Format.RESP;
})
Expand Down
5 changes: 3 additions & 2 deletions src/Follower.ts
@@ -1,4 +1,5 @@
import EventEmitter from 'events';
import { RedisClientOptions } from 'redis';
import { Client, Command, SubCommand } from './Client';
import { Get, Intersects, Nearby, Scan, Search, Within } from './commands';
import {
Expand Down Expand Up @@ -29,10 +30,10 @@ import {
export class Follower extends EventEmitter implements FollowerInterface {
readonly client: Client;

constructor(url: string) {
constructor(url: string, options?: RedisClientOptions) {
super();

this.client = new Client(url).on('error', (error) => {
this.client = new Client(url, options).on('error', (error) => {
/* istanbul ignore next */
this.emit('error', error);
});
Expand Down
18 changes: 12 additions & 6 deletions src/Tile38.ts
@@ -1,3 +1,4 @@
import { RedisClientOptions } from 'redis';
import { Tile38Error } from './errors';
import { Follower } from './Follower';
import { Leader } from './Leader';
Expand All @@ -6,17 +7,22 @@ import { FollowerInterface } from './specs';
export class Tile38 extends Leader {
readonly _follower?: Follower;

/* eslint-disable default-param-last */
constructor(
url = process.env.TILE38_LEADER_URI || process.env.TILE38_URI,
followerUrl = process.env.TILE38_FOLLOWER_URI
followerUrl = process.env.TILE38_FOLLOWER_URI,
options?: RedisClientOptions
) {
super(url as string);
super(url as string, options);

if (followerUrl) {
this._follower = new Follower(followerUrl).on('error', (error) => {
/* istanbul ignore next */
this.emit('error', error);
});
this._follower = new Follower(followerUrl, options).on(
'error',
(error) => {
/* istanbul ignore next */
this.emit('error', error);
}
);
}
}

Expand Down

0 comments on commit af2fb5f

Please sign in to comment.