packages feed

hlrdb 0.1.0.0 → 0.2.0.0

raw patch · 2 files changed

+15/−23 lines, 2 filesdep +timedep −time-extsdep ~hlrdb-corePVP ok

version bump matches the API change (PVP)

Dependencies added: time

Dependencies removed: time-exts

Dependency ranges changed: hlrdb-core

API changes (from Hackage documentation)

- HLRDB: setExpireAt :: MonadRedis m => RedisStructure v a b -> a -> UnixDateTime 'Gregorian -> m ()
- HLRDB: setExpireIn :: MonadRedis m => RedisStructure v a b -> a -> Integer -> m ()
- HLRDB: genId' :: IsIdentifier a => UnixDateTime 'Gregorian -> IO a
+ HLRDB: genId' :: IsIdentifier a => UTCTime -> IO a
- HLRDB: identifierTimestamp :: IsIdentifier a => a -> UnixDateTime 'Gregorian
+ HLRDB: identifierTimestamp :: IsIdentifier a => a -> UTCTime

Files

hlrdb.cabal view
@@ -1,5 +1,5 @@ name:                hlrdb-version:             0.1.0.0+version:             0.2.0.0 synopsis:            High-level Redis Database description:         A library for type-driven interaction with Redis license:             MIT@@ -25,11 +25,11 @@     , cryptonite ^>= 0.24     , hashable ^>= 1.2.6.1     , hedis ^>= 0.10.1-    , hlrdb-core ^>= 0.1+    , hlrdb-core ^>= 0.1.1     , memory ^>= 0.14.8     , random ^>= 1.1     , store ^>= 0.4.3.2-    , time-exts ^>= 3.0+    , time (>=1.6 && <1.9.1) || ^>= 1.9.1     , unordered-containers ^>= 0.2.8.0   hs-source-dirs:      src   default-language:    Haskell2010
src/HLRDB.hs view
@@ -63,8 +63,6 @@        , declareGlobalHSet        , declareGlobalSSet          -- * Other commands-       , setExpireIn-       , setExpireAt        , encodePath        , foldPath        , Store@@ -73,10 +71,9 @@  import HLRDB.Core import HLRDB.Internal--import Data.Time.Exts.Unix-import Data.Time.Exts.Base (Calendar(Gregorian)) import Database.Redis+import Data.Time+import Data.Time.Clock.POSIX import GHC.Int import GHC.Generics import Data.String (IsString(fromString))@@ -134,7 +131,7 @@ -- | Generate a new identifier using the current time as the timestamp {-# INLINE genId #-} genId :: IsIdentifier a => IO a-genId = getCurrentUnixDateTime >>= genId'+genId = getPOSIXTime >>= genIdPOSIX  -- use an offset to make 32-bit timestamps last another 100 years {-# INLINE offset #-}@@ -142,9 +139,13 @@ offset = 2524608000 -- January 1, 2050  -- | Generate a new identifier for the given timestamp-genId' :: IsIdentifier a => UnixDateTime 'Gregorian -> IO a-genId' (UnixDateTime i64) = do-  let t :: Int32 = fromIntegral (i64 - offset)+genId' :: IsIdentifier a => UTCTime -> IO a+genId' =+  genIdPOSIX . utcTimeToPOSIXSeconds++genIdPOSIX :: IsIdentifier a => POSIXTime -> IO a+genIdPOSIX posix = do+  let t :: Int32 = fromIntegral (round posix - offset)   w64 :: Word64 <- randomIO   let (a,w32) = w64tow32w32 w64   let (b,x) = w32tow16w16 w32@@ -162,10 +163,10 @@  -- | Extract the timestamp from an identifier {-# INLINABLE identifierTimestamp #-}-identifierTimestamp :: IsIdentifier a => a -> UnixDateTime 'Gregorian+identifierTimestamp :: IsIdentifier a => a -> UTCTime identifierTimestamp i =   let (Identifier (t,_,_,_)) = toIdentifier i in-  UnixDateTime $ offset + fromIntegral t+  posixSecondsToUTCTime $ fromIntegral $ offset + fromIntegral t  -- Primitive redis key encoding scheme (16 bytes total): -- @@ -308,15 +309,6 @@ declareGlobalSSet :: Store v => PathName -> Maybe TrimScheme -> RedisSSet () v declareGlobalSSet (PathName p) =   RSortedSet $ E (const p) (pure . encode) (decode' . runIdentity)----- | Expire after a given amount of time (in seconds)-setExpireIn :: MonadRedis m => RedisStructure v a b -> a -> Integer -> m ()-setExpireIn p k = liftRedis . ignore . expire (primKey p k)---- | Expire at a given timestamp-setExpireAt :: MonadRedis m => RedisStructure v a b -> a -> UnixDateTime 'Gregorian -> m ()-setExpireAt p k (UnixDateTime t) = liftRedis $ ignore $ expireat (primKey p k) (toInteger t)  scanGlob :: IsIdentifier i => RedisStructure s i v -> ByteString scanGlob = pathGlob . extractPathName