@@ -36,6 +36,7 @@ import System.IO.Unsafe(unsafeInterleaveIO)
3636
3737import Database.Redis.Protocol (Reply (Error ), renderRequest , reply )
3838import qualified Database.Redis.Cluster.Command as CMD
39+ import Network.TLS (ClientParams (.. ))
3940
4041-- This module implements a clustered connection whilst maintaining
4142-- compatibility with the original Hedis codebase. In particular it still
@@ -100,8 +101,8 @@ instance Exception UnsupportedClusterCommandException
100101newtype CrossSlotException = CrossSlotException [[B. ByteString ]] deriving (Show , Typeable )
101102instance Exception CrossSlotException
102103
103- connect :: [CMD. CommandInfo ] -> MVar ShardMap -> Maybe Int -> IO Connection
104- connect commandInfos shardMapVar timeoutOpt = do
104+ connect :: Maybe ClientParams -> [CMD. CommandInfo ] -> MVar ShardMap -> Maybe Int -> IO Connection
105+ connect mTlsParams commandInfos shardMapVar timeoutOpt = do
105106 shardMap <- readMVar shardMapVar
106107 stateVar <- newMVar $ Pending []
107108 pipelineVar <- newMVar $ Pipeline stateVar
@@ -111,7 +112,18 @@ connect commandInfos shardMapVar timeoutOpt = do
111112 nodeConnections shardMap = HM. fromList <$> mapM connectNode (nub $ nodes shardMap)
112113 connectNode :: Node -> IO (NodeID , NodeConnection )
113114 connectNode (Node n _ host port) = do
114- ctx <- CC. connect host (CC. PortNumber $ toEnum port) timeoutOpt
115+ ctx0 <- CC. connect host (CC. PortNumber $ toEnum port) timeoutOpt
116+ ctx <- case mTlsParams of
117+ Nothing -> pure ctx0
118+ Just defaultTlsParams -> do
119+ -- The defaultTlsParams are used to connect to the first
120+ -- host in the cluster, other hosts have different
121+ -- hostnames and so require a different server
122+ -- identification params
123+ let tlsParams = defaultTlsParams {
124+ clientServerIdentification = (host, Char8. pack $ show port)
125+ }
126+ CC. enableTLS tlsParams ctx0
115127 ref <- IOR. newIORef Nothing
116128 return (n, NodeConnection ctx ref n)
117129
0 commit comments