Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: esmooov/rdbhs
base: fccd68dcdb
...
head fork: esmooov/rdbhs
compare: 60fd6161d1
  • 3 commits
  • 2 files changed
  • 2 commit comments
  • 1 contributor
Commits on Mar 14, 2012
Erik Hinton Pre hedis c4c7ec5
Erik Hinton Successful loadingg 3a5cd18
Erik Hinton Test data 60fd616
Showing with 34 additions and 3 deletions.
  1. +34 −3 rdb.hs
  2. BIN  source.rdb
View
37 rdb.hs
@@ -14,8 +14,9 @@ import Control.Monad.IO.Class
import Control.Applicative
import Debug.Trace
import qualified System.IO.Unsafe as IOU
-import Data.Conduit hiding (Done)
+import Data.Conduit hiding (Done,sequence)
import qualified Data.Conduit.Binary as C
+import qualified Database.Redis as R
redisHeader = BL8.pack "REDIS0003"
@@ -138,7 +139,7 @@ loadLzfStr = do
decompressLzfStr :: BL8.ByteString -> B8.ByteString
decompressLzfStr s = B8.concat $ BL8.toChunks str where
- (Right str) = runGetLazy (parseLzf BL8.empty) s
+ (Right !str) = runGetLazy (parseLzf BL8.empty) s
parseLzf :: BL8.ByteString -> Get BL8.ByteString
parseLzf decodedString = do
@@ -474,6 +475,36 @@ pushRDB (Just parser) !input = do liftIO $ mapM_ (\x -> if x == RDBNull then ret
(!st,!p) = repParse input ([],Just parser)
+loadRDB :: ResourceIO m => R.Connection -> Sink B8.ByteString m (R.Redis (Either R.Reply R.Status))
+loadRDB c =
+ sinkState Nothing
+ (pushLoad c)
+ (\state -> return (R.ping))
+
+saveObj :: RDBObj -> R.Redis ()
+saveObj RDBNull = do R.ping >> return ()
+saveObj (RDBPair (exp,key,RDBString val)) = R.set key val >> return ()
+saveObj (RDBPair (exp,key,RDBList vals)) = R.rpush key vals >> return ()
+saveObj (RDBPair (exp,key,RDBSet vals)) = R.sadd key vals >> return ()
+saveObj (RDBPair (exp,key,RDBZSet vals)) = (R.zadd key $ map (\(x,y) -> (y,x)) vals) >> return ()
+saveObj (RDBPair (exp,key,RDBHash vals)) = R.hmset key vals >> return ()
+
+
+pushLoad c Nothing !input = do liftIO $ R.runRedis c $ sequence_ $ map saveObj st
+ return $ StateProcessing p
+ where
+ (Done r l) = runGetPartial (getBytes 9) input
+ (!st,!p) = repParse l ([],Nothing)
+
+pushLoad c (Just parser) !input = do liftIO $ R.runRedis c $ sequence $ map saveObj st
+ return $ StateProcessing p
+ where
+ (!st,!p) = repParse input ([],Just parser)
+
+{-main = do-}
+ {-runResourceT $ C.sourceFile "./dump.rdb" $$ printRDB-}
+
main = do
- runResourceT $ C.sourceFile "./dump.rdb" $$ printRDB
+ conn <- R.connect R.defaultConnectInfo
+ runResourceT $ C.sourceFile "./source.rdb" $$ (loadRDB conn)
View
BIN  source.rdb
Binary file not shown

Showing you all comments on commits in this comparison.

@sripathikrishnan

@esmooov re. test data and test cases - As promised, I created several small dump files and uploaded them over here - https://github.com/sripathikrishnan/redis-rdb-tools/tree/master/tests/dumps. I have a script that generates the rdb files. The unit tests load each of these files and make assertions. See the python scripts at this location - https://github.com/sripathikrishnan/redis-rdb-tools/blob/master/tests/

@esmooov
Owner

@sripathikrishnan that's awesome. checking out.

Something went wrong with that request. Please try again.