Commits

Bryan O'Sullivan committed e42792a

Implement getBucket, setBucket, and mapReduce.

Comments (0)

Files changed (3)

src/Network/Riak.hs

     , delete
     , listBuckets
     , listKeys
+    , getBucket
+    , setBucket
+    , mapReduce
     ) where
 
 import qualified Data.ByteString.Char8 as B
 import Network.Riakclient.RpbGetServerInfoResp
 import Network.Riakclient.RpbListBucketsResp
 import Network.Riakclient.RpbListKeysReq
+import Network.Riakclient.RpbSetBucketReq
 import Network.Riakclient.RpbListKeysResp
 import Network.Riakextra.RpbPingReq
 import Network.Riakextra.RpbGetClientIdReq
 import System.Random
 import Network.Riakclient.RpbGetReq as GetReq
 import Network.Riakclient.RpbGetResp
+import Network.Riakclient.RpbGetBucketReq
+import Network.Riakclient.RpbMapRedReq
+import Network.Riakclient.RpbMapRedResp
+import Network.Riakclient.RpbGetBucketResp as GetBucketResp
 import Network.Riakclient.RpbSetClientIdReq
 import Network.Riakclient.RpbGetClientIdResp as GetClientIdResp
 import Network.Riak.Message
   sendRequest conn $ RpbListKeysReq bucket
   RpbListKeysResp{..} <- recvResponse conn
   return (keys, done)
+
+getBucket :: Connection -> T.Bucket -> IO BucketProps
+getBucket conn bucket = do
+  sendRequest conn $ RpbGetBucketReq bucket
+  GetBucketResp.props <$> recvResponse conn
+
+setBucket :: Connection -> T.Bucket -> BucketProps -> IO ()
+setBucket conn bucket props = do
+  sendRequest conn $ RpbSetBucketReq bucket props
+  recvResponse_ conn SetBucketResp
+
+mapReduce :: Connection -> Job -> IO MapReduce
+mapReduce conn job = do
+  sendRequest conn $ case job of
+                       JSON bs -> RpbMapRedReq bs "application/json"
+                       Erlang bs -> RpbMapRedReq bs "application/x-erlang-binary"
+  recvResponse conn

src/Network/Riak/Message/Tag.hs

 import Network.Riakclient.RpbSetBucketReq
 import Network.Riakclient.RpbListBucketsResp
 import Network.Riakclient.RpbMapRedReq
+import Network.Riakclient.RpbMapRedResp
 import Network.Riakextra.RpbPingReq
 import Network.Riakextra.RpbGetClientIdReq
 import Network.Riakextra.RpbListBucketsReq
 
 instance Request RpbMapRedReq
 
+instance Tagged RpbMapRedResp where
+    messageTag _ = MapRedResp
+    {-# INLINE messageTag #-}
+
+instance Response RpbMapRedResp
+
 putTag :: MessageTag -> Put
 putTag = putWord8 . fromIntegral . fromEnum
 {-# INLINE putTag #-}

src/Network/Riak/Types.hs

     , Client(..)
     , Content
     , ServerInfo
+    , BucketProps
+    , MapReduce
+    , Job(..)
     , Connection(..)
     , Bucket
     , Key
 import Network.Socket
 import Network.Riakclient.RpbContent
 import Network.Riakclient.RpbGetServerInfoResp
+import Network.Riakclient.RpbBucketProps
+import Network.Riakclient.RpbMapRedResp
 import Network.Riak.Types.Internal
     
 type ClientID = L.ByteString
 type Content = RpbContent
 
 type ServerInfo = RpbGetServerInfoResp
+
+type BucketProps = RpbBucketProps
+  
+type MapReduce = RpbMapRedResp
+
+data Job = JSON L.ByteString
+         | Erlang L.ByteString
+           deriving (Eq, Show)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.