Mark Eibes
2020-02-15T10:59:51Z

Main.purs

| 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

Redis.js

| 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) })
| }
| }
| }
| }

Redis.purs

| 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)