{"action":"created","comment":{"url":"https://api.github.com/repos/bustle/redis-loader/pulls/comments/183772500","pull_request_review_id":114834109,"id":183772500,"diff_hunk":"@@ -0,0 +1,437 @@\n+import { EventEmitter } from 'events'\n+import * as DataLoader from 'dataloader'\n+import * as invariant from 'invariant'\n+import { list as redisCommandList } from 'redis-commands'\n+import { ScanStream, ScanStreamOptions } from \"./scan-stream\"\n+import { Redis } from 'ioredis'\n+import { redisMethods } from './interfaces'\n+import { BatchStats, RedisStats } from './stats';\n+\n+export type statsLogger = (stats: RedisStats) => void\n+\n+export interface IRedisLoaderOptions {\n+  redis: Redis\n+  logger?: statsLogger\n+}\n+\n+export class RedisLoader implements redisMethods, EventEmitter {\n+  public stats: RedisStats\n+  public redis: Redis\n+  private logger: statsLogger\n+  private dataLoader: DataLoader<{}, {}>\n+\n+  constructor({ redis, logger }: IRedisLoaderOptions) {\n+    invariant(redis, '\"redis\" is required')\n+    this.logger = logger\n+    this.stats = new RedisStats()\n+    this.redis = redis\n+    this.dataLoader = new DataLoader(commands => this.batchFunction(commands), { cache: false })\n+  }\n+\n+  resetStats() {\n+    this.stats = new RedisStats()\n+  }\n+\n+  get _redis() {\n+    return this.redis\n+  }\n+\n+  startBatch(commands) {\n+    return this.stats.startBatch(commands)\n+  }\n+\n+  endBatch(batchStats, error, response) {\n+    this.stats.endBatch(batchStats, error, response)\n+    this.logStats()\n+  }\n+\n+  logStats() {\n+    if (this.logger) {\n+      this.logger(this.stats)\n+    }\n+  }\n+\n+  async batchFunction(commands) : Promise<any> {\n+    invariant(commands, \"no commands to run\")\n+    const batchStats = this.startBatch(commands)\n+    return this.redis.multi(commands).exec().then(\n+      response => {\n+        this.endBatch(batchStats, null, response)\n+        return response.map(([error, data]) => error || data)\n+      },\n+      error => {\n+        if (Array.isArray(error.previousErrors)) {\n+          error.message = `${error.message}: ${error.previousErrors.map(e => e && e.message)}`\n+        }\n+        this.endBatch(batchStats, error, null)\n+        throw error\n+      }\n+    )\n+  }\n+\n+  // Dynamically generated methods","path":"src/redis-loader.ts","position":73,"original_position":72,"commit_id":"09ff12f96ff801aafe4bfae5425fefbdc57c11c8","original_commit_id":"c5a5c5ad132c2fb7dd749debe09b44c7837fec61","user":{"login":"TSiege","id":6217518,"avatar_url":"https://avatars0.githubusercontent.com/u/6217518?v=4","gravatar_id":"","url":"https://api.github.com/users/TSiege","html_url":"https://github.com/TSiege","followers_url":"https://api.github.com/users/TSiege/followers","following_url":"https://api.github.com/users/TSiege/following{/other_user}","gists_url":"https://api.github.com/users/TSiege/gists{/gist_id}","starred_url":"https://api.github.com/users/TSiege/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TSiege/subscriptions","organizations_url":"https://api.github.com/users/TSiege/orgs","repos_url":"https://api.github.com/users/TSiege/repos","events_url":"https://api.github.com/users/TSiege/events{/privacy}","received_events_url":"https://api.github.com/users/TSiege/received_events","type":"User","site_admin":false},"body":"But if it's also defined in a separate file why not just import that type and use it?","created_at":"2018-04-24T15:16:19Z","updated_at":"2018-04-24T15:16:19Z","html_url":"https://github.com/bustle/redis-loader/pull/7#discussion_r183772500","pull_request_url":"https://api.github.com/repos/bustle/redis-loader/pulls/7","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/comments/183772500"},"html":{"href":"https://github.com/bustle/redis-loader/pull/7#discussion_r183772500"},"pull_request":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/7"}},"in_reply_to_id":183760115},"pull_request":{"url":"https://api.github.com/repos/bustle/redis-loader/pulls/7","id":183588723,"html_url":"https://github.com/bustle/redis-loader/pull/7","diff_url":"https://github.com/bustle/redis-loader/pull/7.diff","patch_url":"https://github.com/bustle/redis-loader/pull/7.patch","issue_url":"https://api.github.com/repos/bustle/redis-loader/issues/7","number":7,"state":"open","locked":false,"title":"lets go full typescript","user":{"login":"reconbot","id":25966,"avatar_url":"https://avatars2.githubusercontent.com/u/25966?v=4","gravatar_id":"","url":"https://api.github.com/users/reconbot","html_url":"https://github.com/reconbot","followers_url":"https://api.github.com/users/reconbot/followers","following_url":"https://api.github.com/users/reconbot/following{/other_user}","gists_url":"https://api.github.com/users/reconbot/gists{/gist_id}","starred_url":"https://api.github.com/users/reconbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reconbot/subscriptions","organizations_url":"https://api.github.com/users/reconbot/orgs","repos_url":"https://api.github.com/users/reconbot/repos","events_url":"https://api.github.com/users/reconbot/events{/privacy}","received_events_url":"https://api.github.com/users/reconbot/received_events","type":"User","site_admin":false},"body":"- Completely new stats interface with multiple inflight batch support\r\n- logger is now only called after a batch command to redis and it's only called with stats\r\n- errors will be returned on each dataloader's promise as necessary\r\n- multi failures will be returned on all the dataloader's promises and saved on the batchStats ","created_at":"2018-04-24T00:05:41Z","updated_at":"2018-04-24T15:16:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76e18e0fe86c323a8326b4754b68b97753670536","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bustle/redis-loader/pulls/7/commits","review_comments_url":"https://api.github.com/repos/bustle/redis-loader/pulls/7/comments","review_comment_url":"https://api.github.com/repos/bustle/redis-loader/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bustle/redis-loader/issues/7/comments","statuses_url":"https://api.github.com/repos/bustle/redis-loader/statuses/09ff12f96ff801aafe4bfae5425fefbdc57c11c8","head":{"label":"bustle:typescript","ref":"typescript","sha":"09ff12f96ff801aafe4bfae5425fefbdc57c11c8","user":{"login":"bustle","id":2198187,"avatar_url":"https://avatars3.githubusercontent.com/u/2198187?v=4","gravatar_id":"","url":"https://api.github.com/users/bustle","html_url":"https://github.com/bustle","followers_url":"https://api.github.com/users/bustle/followers","following_url":"https://api.github.com/users/bustle/following{/other_user}","gists_url":"https://api.github.com/users/bustle/gists{/gist_id}","starred_url":"https://api.github.com/users/bustle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustle/subscriptions","organizations_url":"https://api.github.com/users/bustle/orgs","repos_url":"https://api.github.com/users/bustle/repos","events_url":"https://api.github.com/users/bustle/events{/privacy}","received_events_url":"https://api.github.com/users/bustle/received_events","type":"Organization","site_admin":false},"repo":{"id":127223277,"name":"redis-loader","full_name":"bustle/redis-loader","owner":{"login":"bustle","id":2198187,"avatar_url":"https://avatars3.githubusercontent.com/u/2198187?v=4","gravatar_id":"","url":"https://api.github.com/users/bustle","html_url":"https://github.com/bustle","followers_url":"https://api.github.com/users/bustle/followers","following_url":"https://api.github.com/users/bustle/following{/other_user}","gists_url":"https://api.github.com/users/bustle/gists{/gist_id}","starred_url":"https://api.github.com/users/bustle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustle/subscriptions","organizations_url":"https://api.github.com/users/bustle/orgs","repos_url":"https://api.github.com/users/bustle/repos","events_url":"https://api.github.com/users/bustle/events{/privacy}","received_events_url":"https://api.github.com/users/bustle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bustle/redis-loader","description":"A Redis command batcher","fork":false,"url":"https://api.github.com/repos/bustle/redis-loader","forks_url":"https://api.github.com/repos/bustle/redis-loader/forks","keys_url":"https://api.github.com/repos/bustle/redis-loader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bustle/redis-loader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bustle/redis-loader/teams","hooks_url":"https://api.github.com/repos/bustle/redis-loader/hooks","issue_events_url":"https://api.github.com/repos/bustle/redis-loader/issues/events{/number}","events_url":"https://api.github.com/repos/bustle/redis-loader/events","assignees_url":"https://api.github.com/repos/bustle/redis-loader/assignees{/user}","branches_url":"https://api.github.com/repos/bustle/redis-loader/branches{/branch}","tags_url":"https://api.github.com/repos/bustle/redis-loader/tags","blobs_url":"https://api.github.com/repos/bustle/redis-loader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bustle/redis-loader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bustle/redis-loader/git/refs{/sha}","trees_url":"https://api.github.com/repos/bustle/redis-loader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bustle/redis-loader/statuses/{sha}","languages_url":"https://api.github.com/repos/bustle/redis-loader/languages","stargazers_url":"https://api.github.com/repos/bustle/redis-loader/stargazers","contributors_url":"https://api.github.com/repos/bustle/redis-loader/contributors","subscribers_url":"https://api.github.com/repos/bustle/redis-loader/subscribers","subscription_url":"https://api.github.com/repos/bustle/redis-loader/subscription","commits_url":"https://api.github.com/repos/bustle/redis-loader/commits{/sha}","git_commits_url":"https://api.github.com/repos/bustle/redis-loader/git/commits{/sha}","comments_url":"https://api.github.com/repos/bustle/redis-loader/comments{/number}","issue_comment_url":"https://api.github.com/repos/bustle/redis-loader/issues/comments{/number}","contents_url":"https://api.github.com/repos/bustle/redis-loader/contents/{+path}","compare_url":"https://api.github.com/repos/bustle/redis-loader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bustle/redis-loader/merges","archive_url":"https://api.github.com/repos/bustle/redis-loader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bustle/redis-loader/downloads","issues_url":"https://api.github.com/repos/bustle/redis-loader/issues{/number}","pulls_url":"https://api.github.com/repos/bustle/redis-loader/pulls{/number}","milestones_url":"https://api.github.com/repos/bustle/redis-loader/milestones{/number}","notifications_url":"https://api.github.com/repos/bustle/redis-loader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bustle/redis-loader/labels{/name}","releases_url":"https://api.github.com/repos/bustle/redis-loader/releases{/id}","deployments_url":"https://api.github.com/repos/bustle/redis-loader/deployments","created_at":"2018-03-29T02:05:37Z","updated_at":"2018-04-20T17:40:27Z","pushed_at":"2018-04-24T15:10:22Z","git_url":"git://github.com/bustle/redis-loader.git","ssh_url":"git@github.com:bustle/redis-loader.git","clone_url":"https://github.com/bustle/redis-loader.git","svn_url":"https://github.com/bustle/redis-loader","homepage":null,"size":136,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"bustle:master","ref":"master","sha":"c203fdb02cd24fcba544db8e7ed08fa3f6a270f0","user":{"login":"bustle","id":2198187,"avatar_url":"https://avatars3.githubusercontent.com/u/2198187?v=4","gravatar_id":"","url":"https://api.github.com/users/bustle","html_url":"https://github.com/bustle","followers_url":"https://api.github.com/users/bustle/followers","following_url":"https://api.github.com/users/bustle/following{/other_user}","gists_url":"https://api.github.com/users/bustle/gists{/gist_id}","starred_url":"https://api.github.com/users/bustle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustle/subscriptions","organizations_url":"https://api.github.com/users/bustle/orgs","repos_url":"https://api.github.com/users/bustle/repos","events_url":"https://api.github.com/users/bustle/events{/privacy}","received_events_url":"https://api.github.com/users/bustle/received_events","type":"Organization","site_admin":false},"repo":{"id":127223277,"name":"redis-loader","full_name":"bustle/redis-loader","owner":{"login":"bustle","id":2198187,"avatar_url":"https://avatars3.githubusercontent.com/u/2198187?v=4","gravatar_id":"","url":"https://api.github.com/users/bustle","html_url":"https://github.com/bustle","followers_url":"https://api.github.com/users/bustle/followers","following_url":"https://api.github.com/users/bustle/following{/other_user}","gists_url":"https://api.github.com/users/bustle/gists{/gist_id}","starred_url":"https://api.github.com/users/bustle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bustle/subscriptions","organizations_url":"https://api.github.com/users/bustle/orgs","repos_url":"https://api.github.com/users/bustle/repos","events_url":"https://api.github.com/users/bustle/events{/privacy}","received_events_url":"https://api.github.com/users/bustle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bustle/redis-loader","description":"A Redis command batcher","fork":false,"url":"https://api.github.com/repos/bustle/redis-loader","forks_url":"https://api.github.com/repos/bustle/redis-loader/forks","keys_url":"https://api.github.com/repos/bustle/redis-loader/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bustle/redis-loader/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bustle/redis-loader/teams","hooks_url":"https://api.github.com/repos/bustle/redis-loader/hooks","issue_events_url":"https://api.github.com/repos/bustle/redis-loader/issues/events{/number}","events_url":"https://api.github.com/repos/bustle/redis-loader/events","assignees_url":"https://api.github.com/repos/bustle/redis-loader/assignees{/user}","branches_url":"https://api.github.com/repos/bustle/redis-loader/branches{/branch}","tags_url":"https://api.github.com/repos/bustle/redis-loader/tags","blobs_url":"https://api.github.com/repos/bustle/redis-loader/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bustle/redis-loader/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bustle/redis-loader/git/refs{/sha}","trees_url":"https://api.github.com/repos/bustle/redis-loader/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bustle/redis-loader/statuses/{sha}","languages_url":"https://api.github.com/repos/bustle/redis-loader/languages","stargazers_url":"https://api.github.com/repos/bustle/redis-loader/stargazers","contributors_url":"https://api.github.com/repos/bustle/redis-loader/contributors","subscribers_url":"https://api.github.com/repos/bustle/redis-loader/subscribers","subscription_url":"https://api.github.com/repos/bustle/redis-loader/subscription","commits_url":"https://api.github.com/repos/bustle/redis-loader/commits{/sha}","git_commits_url":"https://api.github.com/repos/bustle/redis-loader/git/commits{/sha}","comments_url":"https://api.github.com/repos/bustle/redis-loader/comments{/number}","issue_comment_url":"https://api.github.com/repos/bustle/redis-loader/issues/comments{/number}","contents_url":"https://api.github.com/repos/bustle/redis-loader/contents/{+path}","compare_url":"https://api.github.com/repos/bustle/redis-loader/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bustle/redis-loader/merges","archive_url":"https://api.github.com/repos/bustle/redis-loader/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bustle/redis-loader/downloads","issues_url":"https://api.github.com/repos/bustle/redis-loader/issues{/number}","pulls_url":"https://api.github.com/repos/bustle/redis-loader/pulls{/number}","milestones_url":"https://api.github.com/repos/bustle/redis-loader/milestones{/number}","notifications_url":"https://api.github.com/repos/bustle/redis-loader/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bustle/redis-loader/labels{/name}","releases_url":"https://api.github.com/repos/bustle/redis-loader/releases{/id}","deployments_url":"https://api.github.com/repos/bustle/redis-loader/deployments","created_at":"2018-03-29T02:05:37Z","updated_at":"2018-04-20T17:40:27Z","pushed_at":"2018-04-24T15:10:22Z","git_url":"git://github.com/bustle/redis-loader.git","ssh_url":"git@github.com:bustle/redis-loader.git","clone_url":"https://github.com/bustle/redis-loader.git","svn_url":"https://github.com/bustle/redis-loader","homepage":null,"size":136,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/7"},"html":{"href":"https://github.com/bustle/redis-loader/pull/7"},"issue":{"href":"https://api.github.com/repos/bustle/redis-loader/issues/7"},"comments":{"href":"https://api.github.com/repos/bustle/redis-loader/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bustle/redis-loader/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/bustle/redis-loader/statuses/09ff12f96ff801aafe4bfae5425fefbdc57c11c8"}},"author_association":"OWNER"}}
{"actor":{"display_login":"TSiege"}}