Skip to content

Commit

Permalink
Merge pull request #209 from sandydoo/fix/resource-pool
Browse files Browse the repository at this point in the history
Fix resource pool conditional compilation
  • Loading branch information
qnikst authored Jun 11, 2023
2 parents c2a433b + b4da23d commit 05861ca
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Database/Redis/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as Char8
import Data.Functor(void)
import qualified Data.IntMap.Strict as IntMap
import Data.Pool(Pool, withResource, createPool, destroyAllResources)
import Data.Pool
( Pool
, withResource
, destroyAllResources
#if MIN_VERSION_resource_pool(0,3,0)
, newPool
, defaultPoolConfig
#else
, createPool
#endif
)
import Data.Typeable
import qualified Data.Time as Time
import Network.TLS (ClientParams)
Expand Down Expand Up @@ -154,10 +164,10 @@ createConnection ConnInfo{..} = do
-- until the first call to the server.
connect :: ConnectInfo -> IO Connection
connect cInfo@ConnInfo{..} = NonClusteredConnection <$>
#if MIN_VERSION_resource_pool(0,4,0)
createPool (createConnection cInfo) PP.disconnect 1 connectMaxIdleTime connectMaxConnections
#if MIN_VERSION_resource_pool(0,3,0)
newPool (defaultPoolConfig (createConnection cInfo) PP.disconnect (realToFrac connectMaxIdleTime) connectMaxConnections)
#else
newPool (defaultPoolConfig (createConnection cInfo) PP.disconnct connectMaxIdleTime connectMaxConnection)
createPool (createConnection cInfo) PP.disconnect 1 connectMaxIdleTime connectMaxConnections
#endif

-- |Constructs a 'Connection' pool to a Redis server designated by the
Expand Down Expand Up @@ -220,10 +230,10 @@ connectCluster bootstrapConnInfo = do
case commandInfos of
Left e -> throwIO $ ClusterConnectError e
Right infos -> do
#if MIN_VERSION_resource_pool(0,4,0)
pool <- createPool (Cluster.connect infos shardMapVar Nothing) Cluster.disconnect 1 (connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo)
#if MIN_VERSION_resource_pool(0,3,0)
pool <- newPool (defaultPoolConfig (Cluster.connect infos shardMapVar Nothing) Cluster.disconnect (realToFrac $ connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo))
#else
pool <- (defaultPoolConfig (Cluster.connect infos shardMapVar Nothing) Cluster.disconnct (connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo))
pool <- createPool (Cluster.connect infos shardMapVar Nothing) Cluster.disconnect 1 (connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo)
#endif
return $ ClusteredConnection shardMapVar pool

Expand Down

0 comments on commit 05861ca

Please sign in to comment.