Created
February 15, 2020 10:59
-
-
Save i-am-the-slime/df22b1d9660ab80d49b3303fc884e012 to your computer and use it in GitHub Desktop.
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
module Main where | |
import Prelude | |
import Debug.Trace (spy) | |
import Effect (Effect) | |
import Effect.Aff (attempt, launchAff_) | |
import Redis (createClient) | |
main :: Effect Unit | |
main = launchAff_ do | |
errOrClient <- attempt $ createClient host port db | |
let _ = spy "client" errOrClient | |
pure unit | |
where | |
host = "127.0.0.1" | |
port = 6379 | |
db = 1 |
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
const redis = require('redis') | |
exports.createClientImpl = function(host) { | |
return function(port) { | |
return function(db) { | |
return function(onError, onSuccess) { | |
const client = redis.createClient({ | |
host: host, | |
port: port, | |
db: db | |
}) | |
client.on("error", onError) | |
client.on("connect", function() { onSuccess(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
module Redis where | |
import Effect.Aff (Aff) | |
import Effect.Aff.Compat (EffectFnAff, fromEffectFnAff) | |
foreign import data RedisClient :: Type | |
foreign import createClientImpl :: String -> Int -> Int -> EffectFnAff RedisClient | |
createClient :: String -> Int -> Int -> Aff RedisClient | |
createClient host port db = fromEffectFnAff (createClientImpl host port db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment