-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,59 @@ | ||
import {RedisClient} from 'redis'; | ||
import IClient from './iclient' | ||
import { RedisClient } from 'redis'; | ||
import IClient from './iclient'; | ||
|
||
const buildRedisClient = (client: RedisClient): IClient => { | ||
const set = <T>(table: string, key: string, value: T) => { | ||
return new Promise<boolean>((resolve, reject) => { | ||
client.hset(table, key, JSON.stringify(value), (err) => { | ||
if (err) { reject(err) }; | ||
client.hset(table, key, JSON.stringify(value), err => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(true); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
const get = <T>(table: string, key: string) => { | ||
return new Promise<T>((resolve, reject) => { | ||
client.hget(table, key, (err, res) => { | ||
if (err) { reject(err) }; | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(JSON.parse(res)); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
const getKeys = (table: string) => { | ||
return new Promise<string[]>((resolve, reject) => { | ||
client.hkeys(table, (err, res) => { | ||
if (err) { reject(err) }; | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(res); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
const getMultiple = <T>(table: string, keyArray: string[]) => { | ||
return new Promise<T[]>((resolve, reject) => { | ||
client.hmget(table, keyArray, (err, res) => { | ||
if (err) { reject(err) }; | ||
if (err) { | ||
reject(err); | ||
} | ||
const parsedRes = res.map(json => JSON.parse(json)); | ||
resolve(parsedRes); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
const result = { | ||
get, | ||
getKeys, | ||
getMultiple, | ||
set, | ||
} | ||
}; | ||
return result; | ||
} | ||
}; | ||
|
||
export default buildRedisClient; | ||
export default buildRedisClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export {default as IClient} from './iclient'; | ||
export {default as buildRedisClient} from './build-redis-client'; | ||
export { default as IClient } from './iclient'; | ||
export { default as buildRedisClient } from './build-redis-client'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export {default as Saga, SagaStatus} from './saga'; | ||
export {default as SagaStep, SagaStepStatus} from './saga-step'; | ||
export { default as Saga, SagaStatus } from './saga'; | ||
export { default as SagaStep, SagaStepStatus } from './saga-step'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export {default as Brokkr} from './brokkr'; | ||
export { default as Brokkr } from './brokkr'; | ||
export * from './entities'; | ||
export * from './clients'; | ||
export * from './clients'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
export interface IHashMap { | ||
[key: string]: any, | ||
[key: string]: any; | ||
} | ||
|
||
export interface ITableMeta { | ||
lastId: number, | ||
}; | ||
lastId: number; | ||
} | ||
|
||
export interface IWorker { | ||
name: string, | ||
run(args: any[], dependencyArgs?:IHashMap): void | ||
} | ||
name: string; | ||
run(args: any[], dependencyArgs?: IHashMap): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters