-
-
Save xiaoDC/669af5c1a5d4b37fe53f979df949bc08 to your computer and use it in GitHub Desktop.
Revisions
-
Brandon Konkle revised this gist
Nov 11, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,7 @@ let make = () : Js.Promise.t(t) => { client, "ready", () => [@bs] resolve({ set: (~key, ~ttl, value) => set(client, key, value, "PX", ttl), get: (~key) => @@ -32,7 +33,7 @@ let make = () : Js.Promise.t(t) => { }) |> ignore ); on(client, "error", (err) => [@bs] reject(err)) } ) }; -
Brandon Konkle revised this gist
Nov 11, 2017 . No changes.There are no files selected for viewing
-
Brandon Konkle renamed this gist
Nov 11, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Brandon Konkle created this gist
Nov 11, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ type ioRedis; [@bs.new] [@bs.module] external ioRedis : unit => ioRedis = "ioredis"; [@bs.send] external set : (ioRedis, string, string, string, int) => Js.Promise.t(string) = ""; [@bs.send] external get : (ioRedis, string) => Js.Promise.t(Js.Nullable.t(string)) = ""; [@bs.send] external on : (ioRedis, string, unit => unit) => unit = ""; type t = { set: (~key: string, ~ttl: int, string) => Js.Promise.t(string), get: (~key: string) => Js.Promise.t(option(string)) }; /** * Initialize a new Redis provider */ let make = () : Js.Promise.t(t) => { let client = ioRedis(); Js.Promise.make( (~resolve, ~reject) => { on( client, "ready", () => resolve({ set: (~key, ~ttl, value) => set(client, key, value, "PX", ttl), get: (~key) => get(client, key) |> Js.Promise.then_((data) => Js.Promise.resolve(Js.Nullable.to_opt(data))) }) |> ignore ); on(client, "error", (err) => reject(err)) } ) };