Commits

Alvaro Videla committed 5de9ac1

implemented RSCC commands

Comments (0)

Files changed (3)

Database/Redis.hs

 module Database.Redis where
+
+import qualified Network
   
 import Database.Redis.Serializable
 import Database.Redis.Key
   lastsave :: a -> IO (Maybe Int)
   
   pong :: a -> IO (Maybe String)
-  -- info :: a -> IO (Maybe [String])
+  
+  info :: a -> IO (Maybe [String])
   -- monitor ::
-  -- slaveoff ::
+  slaveoff :: a -> IO (Bool)
+  slaveoff' :: a -> String -> Int -> IO (Bool)
   
 instance Redis Server where
   get = S.get
   lastsave = P.lastsave
   
   pong = Misc.pong
-  -- info :: a -> IO (Maybe [String])
+
+  info = RSCC.info
   -- monitor ::
-  -- slaveoff ::
-
+  slaveoff = RSCC.slaveoff
+  slaveoff' = RSCC.slaveoff'

Database/Redis/RSCC.hs

 module Database.Redis.RSCC where
-  
+
+-- import qualified Network
+
 import Database.Redis.Protocol
 import Database.Redis.Key
-import Database.Redis.Serializable
+import Database.Redis.Serializable
+
+info :: Server -> IO (Maybe [String])
+info (Server handle ) = do
+  hPutCommand handle ["INFO"]
+  val <- readBulkReply handle
+  case val of
+    Nothing -> return Nothing
+    Just val -> return $ Just (lines val)
+    
+slaveoff :: Server -> IO (Bool)
+slaveoff (Server handle) =  do
+  hPutCommand handle ["SLAVEOFF", "no", "one"]
+  val <- readSingleLineReply handle
+  case val of
+    Just "OK" -> return True
+    _ -> return False
+    
+slaveoff' :: Server -> String -> Int -> IO (Bool)
+slaveoff' (Server handle) host port = do
+  hPutCommand handle ["SLAVEOFF", host, show port]
+  val <- readSingleLineReply handle
+  case val of
+    Just "OK" -> return True
+    _ -> return False
   case rpop of
     Nothing -> putStrLn "rpop lista got Nothing"
     Just v ->  putStrLn ("RPOP: " ++ show (v::String) ++ ".")
+    
+  information <- R.info server
+  case information of
+    Nothing -> putStrLn "info got nothing"
+    Just v -> mapM_ putStrLn v
       
   Single.disconnect server