hedis-config 0.0.3 → 1.0.0
raw patch · 5 files changed
+28/−12 lines, 5 filesdep ~hedisPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hedis
API changes (from Hackage documentation)
- Database.Redis.Config: instance Data.Aeson.Types.Class.FromJSON Database.Redis.Config.RedisConfig
+ Database.Redis.Config: instance Data.Aeson.Types.FromJSON.FromJSON Database.Redis.Config.RedisConfig
Files
- CHANGELOG.md +7/−0
- README.md +1/−0
- examples/redis.yml +1/−0
- hedis-config.cabal +3/−3
- src/Database/Redis/Config.hs +16/−9
CHANGELOG.md view
@@ -1,5 +1,12 @@ # CHANGELOG +## 1.0.0+### Changed+* Compatibility with `hedis >= 0.9.12`+* Not compatible with `hedis < 0.9.12`+### Added+* Connection timeout parameter: `timeout`+ ## 0.0.3 ### Changed * Empty password string will be nullified. Redis counts empty `AUTH` command as
README.md view
@@ -11,6 +11,7 @@ database: 0 # database number to connect to max-connections: 5 # max connections in pool max-idle-time: 30 # keep connection open for 30 seconds+timeout: 30 # connection timeout ``` to your config file, then
examples/redis.yml view
@@ -6,3 +6,4 @@ database: 0 # database number to connect to max-connections: 5 # max connections in pool max-idle-time: 30 # keep connection open for 30 seconds+timeout: 30 # connection timeout
hedis-config.cabal view
@@ -1,5 +1,5 @@ name: hedis-config-version: 0.0.3+version: 1.0.0 synopsis: Easy trivial configuration for Redis description: Datatype to parse redis connection settings from file like .@@ -11,7 +11,7 @@ > database: 0 # database number to connect to > max-connections: 5 # max connections in pool > max-idle-time: 30 # keep connection open for 30 seconds-+ > timeout: 30 # connection timeout license: BSD3 license-file: LICENSE@@ -39,7 +39,7 @@ build-depends: base >= 4.6 && < 5 , aeson , bytestring- , hedis >= 0.6+ , hedis >= 0.9.12 , scientific , text , time
src/Database/Redis/Config.hs view
@@ -29,6 +29,7 @@ database: 0 # database number to connect to max-connections: 5 # max 5 connections in pool max-idle-time: 30 # keep connection open for 30 seconds+timeout: 30 # connection timeout @ -}@@ -42,9 +43,9 @@ parsePort :: Object -> A.Parser (Maybe PortID) parsePort o = optional- $ (fmap (\a -> PortNumber $ floor (a :: Scientific)) (o .: "port"))- <|> (fmap UnixSocket (o .: "socket"))- <|> (fmap Service (o .: "service"))+ $ fmap (\a -> PortNumber $ floor (a :: Scientific)) (o .: "port")+ <|> fmap UnixSocket (o .: "socket")+ <|> fmap Service (o .: "service") parsePassword :: Object -> A.Parser (Maybe BS.ByteString) parsePassword o = do@@ -54,18 +55,24 @@ Just "" -> Nothing Just ps -> Just $ T.encodeUtf8 ps +realToFrac' :: Scientific -> NominalDiffTime+realToFrac' = realToFrac++parseTimeout :: Object -> A.Parser (Maybe (Maybe NominalDiffTime))+parseTimeout o = o .:? "timeout" >>= \mt -> pure (pure (realToFrac' <$> mt))+ instance FromJSON RedisConfig where parseJSON v = RedisConfig <$> withObject "RedisConfig" go v where go o = ConnInfo- <$> (o .:? "host" .!= connectHost defaultConnectInfo)- <*> (parsePort o .!= connectPort defaultConnectInfo)+ <$> o .:? "host" .!= connectHost defaultConnectInfo+ <*> parsePort o .!= connectPort defaultConnectInfo <*> parsePassword o- <*> (o .:? "database" .!= (connectDatabase defaultConnectInfo))- <*> (o .:? "max-connections" .!= (connectMaxConnections defaultConnectInfo))- <*> (fmap (fmap (realToFrac :: Scientific -> NominalDiffTime)) (o .:? "max-idle-time") .!= (connectMaxIdleTime defaultConnectInfo))-+ <*> o .:? "database" .!= connectDatabase defaultConnectInfo+ <*> o .:? "max-connections" .!= connectMaxConnections defaultConnectInfo+ <*> fmap (fmap realToFrac') (o .:? "max-idle-time") .!= connectMaxIdleTime defaultConnectInfo+ <*> parseTimeout o .!= connectTimeout defaultConnectInfo -- | Open redis connection connectRedis :: RedisConfig -> IO Connection