serversession-backend-redis 1.0.5 → 1.0.6
raw patch · 3 files changed
+22/−15 lines, 3 filesdep ~hedisPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: hedis
API changes (from Hackage documentation)
- Web.ServerSession.Backend.Redis.Internal: insertSessionForAuthId :: (RedisCtx m f, Functor m) => SessionId sess -> Maybe AuthId -> m ()
+ Web.ServerSession.Backend.Redis.Internal: insertSessionForAuthId :: forall m (f :: Type -> Type) sess. (RedisCtx m f, Functor m) => SessionId sess -> Maybe AuthId -> m ()
- Web.ServerSession.Backend.Redis.Internal: parseSession :: forall sess. RedisSession sess => SessionId sess -> [(ByteString, ByteString)] -> Maybe (Session sess)
+ Web.ServerSession.Backend.Redis.Internal: parseSession :: RedisSession sess => SessionId sess -> [(ByteString, ByteString)] -> Maybe (Session sess)
- Web.ServerSession.Backend.Redis.Internal: printSession :: forall sess. RedisSession sess => Session sess -> [(ByteString, ByteString)]
+ Web.ServerSession.Backend.Redis.Internal: printSession :: RedisSession sess => Session sess -> [(ByteString, ByteString)]
- Web.ServerSession.Backend.Redis.Internal: removeSessionFromAuthId :: (RedisCtx m f, Functor m) => SessionId sess -> Maybe AuthId -> m ()
+ Web.ServerSession.Backend.Redis.Internal: removeSessionFromAuthId :: forall m (f :: Type -> Type) sess. (RedisCtx m f, Functor m) => SessionId sess -> Maybe AuthId -> m ()
Files
- changelog.md +4/−0
- serversession-backend-redis.cabal +3/−3
- src/Web/ServerSession/Backend/Redis/Internal.hs +15/−12
changelog.md view
@@ -1,3 +1,7 @@+# 1.0.6++* bump hedis to 0.16+ # 1.0.5 * bump hedis to 0.15
serversession-backend-redis.cabal view
@@ -1,10 +1,10 @@ cabal-version: >= 1.10 name: serversession-backend-redis-version: 1.0.5+version: 1.0.6 license: MIT license-file: LICENSE author: Felipe Lessa <felipe.lessa@gmail.com>-maintainer: Michael Xavier <michael@michaelxavier.net>+maintainer: Michael Xavier <michael@michaelxavier.net>, ncaq <ncaq@ncaq.net> synopsis: Storage backend for serversession using Redis. category: Web stability: Stable@@ -28,7 +28,7 @@ build-depends: base == 4.* , bytestring- , hedis == 0.15.*+ , hedis >= 0.16 && < 0.17 , path-pieces , tagged >= 0.7 , text
src/Web/ServerSession/Backend/Redis/Internal.hs view
@@ -32,6 +32,7 @@ import Control.Monad.IO.Class (liftIO) import Data.ByteString (ByteString) import Data.List (partition)+import Data.List.NonEmpty (NonEmpty(..)) import Data.Maybe (fromMaybe, catMaybes) import Data.Proxy (Proxy(..)) import Data.Typeable (Typeable)@@ -43,6 +44,7 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as B8 import qualified Data.HashMap.Strict as HM+import qualified Data.List.NonEmpty as NE import qualified Data.Text.Encoding as TE import qualified Data.Time.Clock as TI import qualified Data.Time.Clock.POSIX as TP@@ -220,12 +222,13 @@ -- | Run the given Redis command in batches of @511*1024@ items. -- This is used for @HMSET@ because there's a hard Redis limit of -- @1024*1024@ arguments to a command. The last result is returned.-batched :: Monad m => ([a] -> m b) -> [a] -> m b+batched :: Monad m => (NonEmpty a -> m b) -> NonEmpty a -> m b batched f xs =- let (this, rest) = splitAt (511*1024) xs- continue | null rest = return- | otherwise = const (batched f rest)- in f this >>= continue+ let (this, rest) = NE.splitAt (511*1024) xs+ thisNE = NE.fromList this+ in case NE.nonEmpty rest of+ Nothing -> f thisNE+ Just restNE -> f thisNE >> batched f restNE -- | Get the session for the given session ID.@@ -241,7 +244,7 @@ Nothing -> return () Just session -> transaction $ do- r <- R.del [rSessionKey sid]+ r <- R.del (rSessionKey sid :| []) removeSessionFromAuthId sid (sessionAuthId session) return (() <$ r) @@ -260,19 +263,19 @@ -- | (Internal) Helper for 'removeSessionFromAuthId' and 'insertSessionForAuthId' fooSessionBarAuthId :: (R.RedisCtx m f, Functor m)- => (ByteString -> [ByteString] -> m (f Integer))+ => (ByteString -> NonEmpty ByteString -> m (f Integer)) -> SessionId sess -> Maybe AuthId -> m () fooSessionBarAuthId _ _ Nothing = return ()-fooSessionBarAuthId fun sid (Just authId) = void $ fun (rAuthKey authId) [rSessionKey sid]+fooSessionBarAuthId fun sid (Just authId) = void $ fun (rAuthKey authId) (rSessionKey sid :| []) -- | Delete all sessions of the given auth ID. deleteAllSessionsOfAuthIdImpl :: AuthId -> R.Redis () deleteAllSessionsOfAuthIdImpl authId = do sessionRefs <- unwrap $ R.smembers (rAuthKey authId)- void $ unwrap $ R.del $ rAuthKey authId : sessionRefs+ void $ unwrap $ R.del (rAuthKey authId :| sessionRefs) -- | Insert a new session.@@ -286,7 +289,7 @@ Nothing -> do transaction $ do let sk = rSessionKey sid- r <- batched (R.hmset sk) (printSession session)+ r <- batched (R.hmset sk) (NE.fromList $ printSession session) expireSession session sto insertSessionForAuthId (sessionKey session) (sessionAuthId session) return (() <$ r)@@ -304,8 +307,8 @@ transaction $ do -- Delete the old session and set the new one. let sk = rSessionKey sid- _ <- R.del [sk]- r <- batched (R.hmset sk) (printSession session)+ _ <- R.del (sk :| [])+ r <- batched (R.hmset sk) (NE.fromList $ printSession session) expireSession session sto -- Remove the old auth ID from the map if it has changed.