Skip to content
Browse files

Move all transaction commands into their own module: Database.Redis.T…

…ransactions. Three commands are exported: watch, unwatch, multiExec. Queued-wrapped values are ignored, so far.
  • Loading branch information...
1 parent e853483 commit d2b7d095fad6e07a4d383cfa109c4c0b6f7ae1b8 @informatikr committed Feb 24, 2012
Showing with 47 additions and 42 deletions.
  1. +3 −5 codegen/GenCmds.hs
  2. +1 −0 hedis.cabal
  3. +6 −2 src/Database/Redis.hs
  4. +0 −33 src/Database/Redis/Commands.hs
  5. +2 −2 src/Database/Redis/Core.hs
  6. +35 −0 src/Database/Redis/Transactions.hs
View
8 codegen/GenCmds.hs
@@ -40,7 +40,7 @@ groupCmds (Cmds cmds) =
, "sorted_set"
, "hash"
-- , "pubsub" commands implemented in Database.Redis.PubSub
- , "transactions"
+ -- , "transactions" implemented in Database.Redis.Transactions
, "connection"
, "server"
]
@@ -113,12 +113,10 @@ instance FromJSON Cmds where
let cmdName = unpack $ encodeUtf8 name
cmdGroup <- cmd .: "group"
cmdRetType <- cmd .:? "returns"
- cmdSummary <- escape <$> cmd .: "summary"
+ cmdSummary <- cmd .: "summary"
cmdArgs <- cmd .:? "arguments" .!= []
<|> error ("failed to parse args: " ++ cmdName)
return Cmd{..})
- where
- escape = concatMap $ \c -> if c == '/' then "\\/" else [c]
instance FromJSON Arg where
parseJSON (Object arg) = asum
@@ -220,7 +218,7 @@ exportList cmds =
"sorted_set" -> "Sorted Sets"
"hash" -> "Hashes"
-- "pubsub" ->
- "transactions" -> "Transactions"
+ -- "transactions" -> "Transactions"
"connection" -> "Connection"
"server" -> "Server"
_ -> error $ "untranslated group: " ++ cmdGroup
View
1 hedis.cabal
@@ -78,6 +78,7 @@ library
Database.Redis.PubSub,
Database.Redis.Reply,
Database.Redis.Request,
+ Database.Redis.Transactions,
Database.Redis.Types
Database.Redis.Commands,
Database.Redis.ManualCommands
View
8 src/Database/Redis.hs
@@ -55,7 +55,6 @@ module Database.Redis (
-- 'RedisTx'.
Redis(), runRedis,
RedisTx(),
- Queued,
RedisCtx, MonadRedis,
-- * Connection
@@ -65,7 +64,11 @@ module Database.Redis (
-- * Commands
module Database.Redis.Commands,
-
+
+ -- * Transactions
+ module Database.Redis.Transactions,
+ Queued(),
+
-- * Pub\/Sub
module Database.Redis.PubSub,
@@ -88,6 +91,7 @@ module Database.Redis (
import Database.Redis.Core
import Database.Redis.PubSub
import Database.Redis.Reply
+import Database.Redis.Transactions
import Database.Redis.Types
import Database.Redis.Commands
View
33 src/Database/Redis/Commands.hs
@@ -152,13 +152,6 @@ setnx, -- |Set the value of a key, only if the key does not exist (<http://redis
setrange, -- |Overwrite part of a string at key starting at the specified offset (<http://redis.io/commands/setrange>).
strlen, -- |Get the length of the value stored in a key (<http://redis.io/commands/strlen>).
--- ** Transactions
-discard, -- |Discard all commands issued after MULTI (<http://redis.io/commands/discard>).
-exec, -- |Execute all commands issued after MULTI (<http://redis.io/commands/exec>).
-multi, -- |Mark the start of a transaction block (<http://redis.io/commands/multi>).
-unwatch, -- |Forget about all watched keys (<http://redis.io/commands/unwatch>).
-watch, -- |Watch the given keys to determine execution of the MULTI\/EXEC block (<http://redis.io/commands/watch>).
-
-- * Unimplemented Commands
-- |These commands are not implemented, as of now. Library
-- users can implement these or other commands from
@@ -289,11 +282,6 @@ move
-> m (Either Reply a)
move key db = sendRequest (["MOVE"] ++ [encode key] ++ [encode db] )
-multi
- :: (RedisCtx m Status a)
- => m (Either Reply a)
-multi = sendRequest (["MULTI"] )
-
getrange
:: (RedisCtx m ByteString a)
=> ByteString -- ^ key
@@ -309,12 +297,6 @@ srem
-> m (Either Reply a)
srem key member = sendRequest (["SREM"] ++ [encode key] ++ map encode member )
-watch
- :: (RedisCtx m Status a)
- => [ByteString] -- ^ key
- -> m (Either Reply a)
-watch key = sendRequest (["WATCH"] ++ map encode key )
-
getbit
:: (RedisCtx m Integer a)
=> ByteString -- ^ key
@@ -478,11 +460,6 @@ decrby
-> m (Either Reply a)
decrby key decrement = sendRequest (["DECRBY"] ++ [encode key] ++ [encode decrement] )
-exec
- :: (RedisCtx m Reply a)
- => m (Either Reply a)
-exec = sendRequest (["EXEC"] )
-
mget
:: (RedisCtx m [Maybe ByteString] a)
=> [ByteString] -- ^ key
@@ -824,11 +801,6 @@ strlen
-> m (Either Reply a)
strlen key = sendRequest (["STRLEN"] ++ [encode key] )
-unwatch
- :: (RedisCtx m Status a)
- => m (Either Reply a)
-unwatch = sendRequest (["UNWATCH"] )
-
hset
:: (RedisCtx m Bool a)
=> ByteString -- ^ key
@@ -844,11 +816,6 @@ lpushx
-> m (Either Reply a)
lpushx key value = sendRequest (["LPUSHX"] ++ [encode key] ++ [encode value] )
-discard
- :: (RedisCtx m Status a)
- => m (Either Reply a)
-discard = sendRequest (["DISCARD"] )
-
debugSegfault
:: (RedisCtx m Status a)
=> m (Either Reply a)
View
4 src/Database/Redis/Core.hs
@@ -6,8 +6,8 @@ module Database.Redis.Core (
Connection(..), connect,
ConnectInfo(..), defaultConnectInfo,
Redis(),runRedis,
- RedisTx(),
- Queued(),
+ RedisTx(..),
+ Queued,
RedisCtx(), MonadRedis(),
send, recv, sendRequest,
HostName, PortID(..),
View
35 src/Database/Redis/Transactions.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Database.Redis.Transactions (
+ watch, unwatch, multiExec,
+) where
+
+import Data.ByteString
+
+import Database.Redis.Core
+import Database.Redis.Reply
+import Database.Redis.Types
+
+-- |Watch the given keys to determine execution of the MULTI\/EXEC block
+-- (<http://redis.io/commands/watch>).
+watch
+ :: [ByteString] -- ^ key
+ -> Redis (Either Reply Status)
+watch key = sendRequest ("WATCH" : key)
+
+-- |Forget about all watched keys (<http://redis.io/commands/unwatch>).
+unwatch :: Redis (Either Reply Status)
+unwatch = sendRequest ["UNWATCH"]
+
+
+multiExec :: RedisTx (Queued a) -> Redis (Either Reply Reply)
+multiExec (RedisTx tx) = do
+ _ <- multi
+ _ <- tx
+ exec
+
+multi :: Redis (Either Reply Status)
+multi = sendRequest ["MULTI"]
+
+exec :: Redis (Either Reply Reply)
+exec = sendRequest ["EXEC"]

0 comments on commit d2b7d09

Please sign in to comment.
Something went wrong with that request. Please try again.