packages feed

hedis-pile 0.5.3 → 0.6.0

raw patch · 3 files changed

+19/−18 lines, 3 filesdep ~hedisdep ~hedis-tagsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hedis, hedis-tags

API changes (from Hackage documentation)

- Database.Redis.Pile: pile :: (MonadIO ma, ma ~ Redis, Binary d) => ByteString -> ByteString -> Maybe ByteString -> (forall mb. MonadIO mb => mb (d, ByteString, [ByteString], Maybe Integer)) -> ma (Maybe d)
+ Database.Redis.Pile: pile :: (MonadIO ma, RedisCtx ma (Either t), Binary d) => ByteString -> ByteString -> Maybe ByteString -> (forall mb. MonadIO mb => mb (d, ByteString, [ByteString], Integer)) -> ma (Maybe d)

Files

hedis-pile.cabal view
@@ -1,5 +1,5 @@ name:           hedis-pile
-version:        0.5.3
+version:        0.6.0
 cabal-version:  >= 1.8
 build-type:     Simple
 stability:      Experimental
@@ -22,8 +22,8 @@                    base >= 4 && < 5,
                    bytestring >= 0.9 && < 0.10,
                    binary,
-                   hedis >= 0.4 && < 0.5,
-                   hedis-tags >= 0.1,
+                   hedis >= 0.5 && < 0.6,
+                   hedis-tags >= 0.2,
                    string-conversions,
                    transformers >= 0.2 && < 0.4
   ghc-options:     -Wall
@@ -45,7 +45,7 @@                    
                    -- from lib
                    bytestring >= 0.9 && < 0.10,
-                   hedis >= 0.4 && < 0.5,
+                   hedis >= 0.5 && < 0.6,
  
                    binary,
                    lifted-base,
src/Database/Redis/Pile.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE RankNTypes #-}
-{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE FlexibleContexts #-}
 
 -- | Solution for caching mandatory data with Redis.
 --   
@@ -18,7 +18,6 @@ ) where
 
 import Control.Monad.IO.Class (MonadIO)
-import Control.Monad (void)
 
 import qualified Data.ByteString as B
 import Data.Binary (Binary(..), encode, decode)
@@ -47,7 +46,7 @@ --   
 --   * In all other cases time complexity does not make sense
 
-pile :: forall ma d . (MonadIO ma, ma ~ R.Redis, Binary d) => 
+pile :: forall ma d t . (MonadIO ma,  R.RedisCtx ma (Either t), Binary d) => 
        B.ByteString
             -- ^ Prefix for key and tags.
     -> B.ByteString        
@@ -57,9 +56,9 @@             --   'pile' will return 'Nothing'. This is very useful when data in 
             --   cache can be described with hash. For example, webpage ETag.
     -> (forall mb . (MonadIO mb) => 
-            mb (d, B.ByteString, [B.ByteString], Maybe Integer))
+            mb (d, B.ByteString, [B.ByteString], Integer))
             -- ^ Computation that returns data, expect value, tags and 
-            --   optional TTL. 
+            --   optional TTL (set it to zero for no expiration). 
             --   All tags will be stored as @prefix:tag@.
     -> ma (Maybe d)
 pile keyPrefix key (Just ev) fn = do
@@ -90,7 +89,7 @@         case maybeInCache of
             Right Nothing -> do
                 -- no data in cache. store and return
-                void $ R.hmset withPrefix 
+                _ <- R.hmset withPrefix 
                     [("e", newExpectValue), ("d", encodedData)]
                 setExpire ttl
                 RT.markTags [withPrefix] keyPrefix tags
@@ -103,8 +102,10 @@                 return $ Just newData
         
       where
-        setExpire Nothing = return ()
-        setExpire (Just ke) = void $ R.expire withPrefix ke
+        setExpire 0 = return ()
+        setExpire ke = do
+            _ <- R.expire withPrefix ke
+            return ()
 
 
 
test/Database/Redis/Test/Pile.hs view
@@ -76,7 +76,7 @@     setup
     teardown $ runInRedis $ do
         r <- RP.pile testPrefix (toBs 1) Nothing $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         liftIO $ r @=? Just (testData 1)
 
 -- | Work without tag
@@ -85,9 +85,9 @@     setup
     teardown $ runInRedis $ do
         r1 <- RP.pile testPrefix (toBs 1) Nothing $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         (r2 :: Maybe TData) <- RP.pile testPrefix (toBs 1) Nothing $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         liftIO $ r1 @=? r2
 
 -- | Work with tag
@@ -97,14 +97,14 @@     teardown $ runInRedis $ do
         -- prepend data
         _ <- RP.pile testPrefix (toBs 1) (Just "exp") $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         -- retrieve with matching expect
         r2 <- RP.pile testPrefix (toBs 1) (Just "exp") $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         liftIO $ r2 @=? Nothing
         -- retrieve with unmatching expect
         r3 <- RP.pile testPrefix (toBs 1) (Just "exp_no_match") $ 
-                return (testData 1, "exp", [], Nothing)
+                return (testData 1, "exp", [], 0)
         liftIO $ r3 @=? Just (testData 1)
 
 -- | Run in redis