summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillLangstroth <>2010-11-14 20:19:55 (GMT)
committerLuite Stegeman <luite@luite.com>2010-11-14 20:19:55 (GMT)
commit2e0d61f4cc7e413d597949e7fe5bb616611da8d0 (patch)
treed4fef3f3cc8c803d11dd2bad632e14a591a207cd
parenta707321149171a62e35da6259092707007959342 (diff)
version 0.0.130.0.13
-rw-r--r--redis-hs.cabal5
-rw-r--r--src/Database/Redis.hs2
-rw-r--r--src/Database/Redis/General.hs17
-rw-r--r--src/Database/Redis/Internal.hs7
-rw-r--r--src/Database/Redis/List.hs34
-rw-r--r--src/Database/Redis/String.hs14
-rw-r--r--src/Database/Redis/Transaction.hs28
-rw-r--r--test/redis-tests.cabal2
-rw-r--r--test/suite/Database/Redis/List/Tests.hs16
-rw-r--r--test/suite/TestSuite.hs3
10 files changed, 89 insertions, 39 deletions
diff --git a/redis-hs.cabal b/redis-hs.cabal
index e2d1c06..41643a1 100644
--- a/redis-hs.cabal
+++ b/redis-hs.cabal
@@ -1,5 +1,5 @@
name: redis-hs
-version: 0.0.12
+version: 0.0.13
author: Will Langstroth <will@langstroth.com>
maintainer: Will Langstroth <will@langstroth.com>
license: MIT
@@ -44,7 +44,8 @@ library
Database.Redis.General,
Database.Redis.String,
Database.Redis.List,
- Database.Redis.Set
+ Database.Redis.Set,
+ Database.Redis.Transaction
build-depends:
base == 4.*,
diff --git a/src/Database/Redis.hs b/src/Database/Redis.hs
index 6ea5f8b..dc78cf3 100644
--- a/src/Database/Redis.hs
+++ b/src/Database/Redis.hs
@@ -4,6 +4,7 @@ module Database.Redis
, module Database.Redis.String
, module Database.Redis.List
, module Database.Redis.Set
+ , module Database.Redis.Transaction
-- , module Database.Redis.SortedSet
-- , module Database.Redis.Hash
) where
@@ -13,5 +14,6 @@ import Database.Redis.General
import Database.Redis.String
import Database.Redis.List
import Database.Redis.Set
+import Database.Redis.Transaction
-- import Database.Redis.SortedSet
-- import Database.Redis.Hash
diff --git a/src/Database/Redis/General.hs b/src/Database/Redis/General.hs
index d727b3a..3d4f84d 100644
--- a/src/Database/Redis/General.hs
+++ b/src/Database/Redis/General.hs
@@ -1,20 +1,15 @@
module Database.Redis.General
( RedisReply(..)
- , keyExists
- , keyExistsB
- , keyDelete
- , keyDeleteB
- , keyType
- , keyTypeB
- , keys
- , keysB
+ , keyExists, keyExistsB
+ , keyDelete, keyDeleteB
+ , keyType, keyTypeB
+ , keys, keysB
, keyRandom
, keyRename
, select
, toUTF8
, ping
- , unwrapReply
- , unwrapReplyB
+ , unwrapReply, unwrapReplyB
) where
import Data.Maybe
@@ -96,7 +91,7 @@ keyRandom :: Handle
keyRandom h = request h [toUTF8 "RANDOMKEY"]
--- | RENAME
+-- | Calls @RENAME@ (<http://code.google.com/p/redis/wiki/RenameCommand>)
keyRename :: Handle
-> String -- ^ old key name
-> String -- ^ new key name
diff --git a/src/Database/Redis/Internal.hs b/src/Database/Redis/Internal.hs
index cdcf5d3..2b61db2 100644
--- a/src/Database/Redis/Internal.hs
+++ b/src/Database/Redis/Internal.hs
@@ -1,5 +1,6 @@
{-
--- | This module processes requests and replies.
+-- | This module processes requests and replies, and contains some utility
+-- functions
-}
module Database.Redis.Internal
@@ -38,7 +39,9 @@ send h req = B.hPut h req >> B.hPut h (toUTF8 crlf) >>
------------------------------------------------------------------------------
-- | Formats and sends the request
-request :: Handle -> [ByteString] -> IO (Maybe RedisReply)
+request :: Handle
+ -> [ByteString] -- ^ list of requests
+ -> IO (Maybe RedisReply)
request _ [] = return $ Just (RedisInteger 0)
request h commandList = send h $
B.concat [ bulkLength commandList
diff --git a/src/Database/Redis/List.hs b/src/Database/Redis/List.hs
index f4cbd4f..374141c 100644
--- a/src/Database/Redis/List.hs
+++ b/src/Database/Redis/List.hs
@@ -1,23 +1,19 @@
{-
-- | This module interacts with the list structure in Redis. All the functions
--- take either 'String' or 'ByteString' arguments, but send 'ByteString'
+-- take either 'String' or 'ByteString' arguments, but send 'ByteString'
-- 'request's regardless.
-}
module Database.Redis.List
- ( listRightPush
- , listRightPushB
- , listLeftPush
- , listLeftPushB
- , listLength
- , listLengthB
- , listRange
- , listRangeB
- , listIndex
- , listIndexB
- , listRemove
+ ( listRightPush, listRightPushB
+ , listLeftPush, listLeftPushB
+ , listLength, listLengthB
+ , listRange, listRangeB
+ , listIndex, listIndexB
+ , listRemove, listRemoveB
) where
+
import System.IO
import Database.Redis.Internal
@@ -109,8 +105,8 @@ listIndex h key index =
-- | Calls `LINDEX` with 'ByteString' and 'Int' arguments
listIndexB :: Handle
- -> ByteString -- ^ key
- -> Int -- ^ index
+ -> ByteString -- ^ key
+ -> Int -- ^ index
-> IO (Maybe RedisReply)
listIndexB h key index =
request h [toUTF8 "LINDEX", key, toUTF8 $ show index]
@@ -136,6 +132,16 @@ listRemove h key num value =
request h $ map toUTF8 ["LREM", key, show num, value]
+-- | Calls `LREM` with 'ByteString' and 'Int' arguments.
+listRemoveB :: Handle
+ -> ByteString -- ^ key
+ -> Int -- ^ the number of items to delete (sign is direction)
+ -> ByteString -- ^ value
+ -> IO (Maybe RedisReply)
+listRemoveB h key num value =
+ request h [toUTF8 "LREM", key, toUTF8 $ show num, value]
+
+
-- LPOP
-- RPOP
-- BLPOP
diff --git a/src/Database/Redis/String.hs b/src/Database/Redis/String.hs
index 919c104..16050e0 100644
--- a/src/Database/Redis/String.hs
+++ b/src/Database/Redis/String.hs
@@ -1,8 +1,6 @@
module Database.Redis.String
- ( itemSet
- , itemSetB
- , itemGet
- , itemGetB
+ ( itemSet, itemSetB
+ , itemGet, itemGetB
) where
@@ -12,7 +10,7 @@ import Database.Redis.Internal
------------------------------------------------------------------------------
--- SET
+-- | SET
itemSet :: Handle
-> String -- ^ key to set
-> String -- ^ value to set
@@ -20,7 +18,7 @@ itemSet :: Handle
itemSet h key value = request h $ map toUTF8 ["SET", key, value]
--- SET for ByteString input
+-- | SET for ByteString input
itemSetB :: Handle
-> ByteString -- ^ key to set
-> ByteString -- ^ value to set
@@ -29,13 +27,13 @@ itemSetB h key value = request h [toUTF8 "SET", key, value]
------------------------------------------------------------------------------
--- GET
+-- | GET
itemGet :: Handle
-> String -- ^ key of the value to return
-> IO (Maybe RedisReply)
itemGet h key = request h $ map toUTF8 ["GET", key]
--- GET for ByteString input
+-- | GET for ByteString input
itemGetB :: Handle
-> ByteString -- ^ key of the value to return
-> IO (Maybe RedisReply)
diff --git a/src/Database/Redis/Transaction.hs b/src/Database/Redis/Transaction.hs
new file mode 100644
index 0000000..6602ce4
--- /dev/null
+++ b/src/Database/Redis/Transaction.hs
@@ -0,0 +1,28 @@
+-- | This module corresponds to the transaction commands introduced in Redis
+-- 2.0, explained at <http://code.google.com/p/redis/wiki/MultiExecCommand>
+
+module Database.Redis.Transaction
+ ( multi
+ , exec
+ ) where
+
+
+import System.IO
+
+import Database.Redis.Internal
+
+
+------------------------------------------------------------------------------
+-- | MULTI, begin a transaction
+multi :: Handle
+ -> IO (Maybe RedisReply)
+multi h = request h [toUTF8 "MULTI"]
+
+
+------------------------------------------------------------------------------
+-- | EXEC, execute the transaction
+exec :: Handle
+ -> IO (Maybe RedisReply)
+exec h = request h [toUTF8 "EXEC"]
+
+
diff --git a/test/redis-tests.cabal b/test/redis-tests.cabal
index fa0f96c..737bbba 100644
--- a/test/redis-tests.cabal
+++ b/test/redis-tests.cabal
@@ -1,5 +1,5 @@
name: redis-tests
-version: 0.0.12
+version: 0.0.13
build-type: Simple
cabal-version: >= 1.6
diff --git a/test/suite/Database/Redis/List/Tests.hs b/test/suite/Database/Redis/List/Tests.hs
index 6701939..0eaf650 100644
--- a/test/suite/Database/Redis/List/Tests.hs
+++ b/test/suite/Database/Redis/List/Tests.hs
@@ -30,6 +30,7 @@ tests = [ testCase "redis listRightPush" listRightPushTest
, testCase "redis listRange" listRangeTest
, testCase "redis listRangeB" listRangeBTest
, testCase "redis listRemove" listRemoveTest
+ , testCase "redis listRemoveB" listRemoveBTest
]
@@ -183,6 +184,19 @@ listRemoveTest = do
returning <- listRemove con "rlist" (-1) "value"
_ <- keyDelete con ["rlist"]
disconnect con
- H.assertEqual "listLeftPush" (Just $ RedisInteger 1) returning
+ H.assertEqual "listRemove" (Just $ RedisInteger 1) returning
+
+
+------------------------------------------------------------------------------
+listRemoveBTest :: H.Assertion
+listRemoveBTest = do
+ con <- connect localhost defaultPort
+ _ <- select con 0
+ _ <- listRightPush con "rlistb" "value"
+ _ <- listRightPush con "rlistb" "value"
+ returning <- listRemoveB con (toUTF8 "rlistb") (-1) (toUTF8 "value")
+ _ <- keyDelete con ["rlistb"]
+ disconnect con
+ H.assertEqual "listRemove" (Just $ RedisInteger 1) returning
diff --git a/test/suite/TestSuite.hs b/test/suite/TestSuite.hs
index a090b76..8bd9485 100644
--- a/test/suite/TestSuite.hs
+++ b/test/suite/TestSuite.hs
@@ -8,6 +8,7 @@ import qualified Database.Redis.Connection.Tests
import qualified Database.Redis.String.Tests
import qualified Database.Redis.List.Tests
import qualified Database.Redis.Set.Tests
+-- import qualified Database.Redis.Transaction.Tests
main :: IO ()
@@ -22,4 +23,6 @@ main = defaultMain tests
Database.Redis.List.Tests.tests
, testGroup "Database.Redis.Set.Tests"
Database.Redis.Set.Tests.tests
+ -- , testGroup "Database.Redis.Transaction.Tests"
+ -- Database.Redis.Transaction.Tests.tests
]