module Database.Redis.IO.Settings where
import Data.Time
import Data.Word
import Database.Redis.IO.Types (Milliseconds (..))
data Settings = Settings
{ sHost :: String
, sPort :: Word16
, sIdleTimeout :: NominalDiffTime
, sMaxConnections :: Int
, sPoolStripes :: Int
, sMaxWaitQueue :: Maybe Word64
, sConnectTimeout :: Milliseconds
, sSendRecvTimeout :: Milliseconds
}
defSettings :: Settings
defSettings = Settings "localhost" 6379
60
25
2
Nothing
5000
10000
setHost :: String -> Settings -> Settings
setHost v s = s { sHost = v }
setPort :: Word16 -> Settings -> Settings
setPort v s = s { sPort = v }
setIdleTimeout :: NominalDiffTime -> Settings -> Settings
setIdleTimeout v s = s { sIdleTimeout = v }
setMaxConnections :: Int -> Settings -> Settings
setMaxConnections v s = s { sMaxConnections = v }
setMaxWaitQueue :: Word64 -> Settings -> Settings
setMaxWaitQueue v s = s { sMaxWaitQueue = Just v }
setPoolStripes :: Int -> Settings -> Settings
setPoolStripes v s
| v < 1 = error "Network.Redis.IO.Settings: at least one stripe required"
| otherwise = s { sPoolStripes = v }
setConnectTimeout :: NominalDiffTime -> Settings -> Settings
setConnectTimeout v s = s { sConnectTimeout = Ms $ round (1000 * v) }
setSendRecvTimeout :: NominalDiffTime -> Settings -> Settings
setSendRecvTimeout v s = s { sSendRecvTimeout = Ms $ round (1000 * v) }