Skip to content

Commit

Permalink
add Redis prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryuk committed Jan 19, 2021
1 parent 7efd752 commit 38956fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class RedisBalancer {
*
* @param data not empty array of functions
* @param redisClient
* @param redisPrefix
*/
constructor(data, redisClient) {
constructor(data, redisClient, redisPrefix) {
this._STORE_PREFIX = 'balancer';
this.INC_VALUE = 1;
this.redisPrefix = redisPrefix;
this._redisClient = redisClient;
this._data = data;
this._storeKey = this.makeStoreKey(data);
Expand Down Expand Up @@ -85,7 +87,7 @@ class RedisBalancer {
* @protected
*/
makeStoreKey(data) {
let storeKeyArray = [this._STORE_PREFIX];
let storeKeyArray = [this._STORE_PREFIX, this.redisPrefix];
data.forEach((method, index) => {
storeKeyArray.push(index.toString());
});
Expand Down
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class RedisBalancer<T> {
private _data: Array<T>;
private readonly _STORE_PREFIX = 'balancer';
private readonly _redisClient: RedisClient;
private readonly redisPrefix: string;
private readonly INC_VALUE = 1;

private readonly _functions: RedisFunctions;
Expand All @@ -21,8 +22,10 @@ export default class RedisBalancer<T> {
*
* @param data not empty array of functions
* @param redisClient
* @param redisPrefix
*/
constructor(data: Array<T>, redisClient: RedisClient) {
constructor(data: Array<T>, redisClient: RedisClient, redisPrefix: string) {
this.redisPrefix = redisPrefix;
this._redisClient = redisClient;
this._data = data;
this._storeKey = this.makeStoreKey(data);
Expand Down Expand Up @@ -78,7 +81,7 @@ export default class RedisBalancer<T> {
* @protected
*/
protected makeStoreKey(data: Array<T>): string {
let storeKeyArray: Array<string> = [this._STORE_PREFIX];
let storeKeyArray: Array<string> = [this._STORE_PREFIX, this.redisPrefix];
data.forEach((method: T, index: number) => {
storeKeyArray.push(index.toString());
});
Expand Down

0 comments on commit 38956fc

Please sign in to comment.