-- | Module containing all the functions necessary to make a connection to
-- the Redis server.

module Database.Redis.Connection
    ( defaultPort
    , localhost
    , connect
    , disconnect
    ) where


import           Network
import           System.IO


------------------------------------------------------------------------------
defaultPort :: PortNumber
defaultPort = 6379 :: PortNumber


------------------------------------------------------------------------------
localhost :: HostName
localhost = "127.0.0.1" :: HostName


------------------------------------------------------------------------------
connect :: HostName -> PortNumber -> IO Handle
connect host port =
    withSocketsDo $ do
        h <- connectTo host (PortNumber port)
        hSetNewlineMode h (NewlineMode CRLF CRLF)
        hSetBuffering h NoBuffering
        return h


------------------------------------------------------------------------------
disconnect :: Handle -> IO ()
disconnect h = hClose h


-- AUTH