Skip to content

Instantly share code, notes, and snippets.

@i-am-the-slime
Created February 15, 2020 10:59
Show Gist options
  • Save i-am-the-slime/df22b1d9660ab80d49b3303fc884e012 to your computer and use it in GitHub Desktop.
Save i-am-the-slime/df22b1d9660ab80d49b3303fc884e012 to your computer and use it in GitHub Desktop.
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
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) })
}
}
}
}
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