From af2fb5fbe6efff8ee32fca2e1e8dc05cc16989df Mon Sep 17 00:00:00 2001 From: Benjamin Ramser Date: Tue, 6 Jun 2023 08:51:32 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20optional=20RedisCli?= =?UTF-8?q?entOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Client.ts | 6 +++--- src/Follower.ts | 5 +++-- src/Tile38.ts | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index ef8334f..bbeff99 100644 --- a/src/Client.ts +++ b/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'; @@ -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; }) diff --git a/src/Follower.ts b/src/Follower.ts index 36352c9..f679f02 100644 --- a/src/Follower.ts +++ b/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 { @@ -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); }); diff --git a/src/Tile38.ts b/src/Tile38.ts index edba8aa..42880ba 100644 --- a/src/Tile38.ts +++ b/src/Tile38.ts @@ -1,3 +1,4 @@ +import { RedisClientOptions } from 'redis'; import { Tile38Error } from './errors'; import { Follower } from './Follower'; import { Leader } from './Leader'; @@ -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); + } + ); } }