summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillLangstroth <>2010-11-09 01:25:43 (GMT)
committerLuite Stegeman <luite@luite.com>2010-11-09 01:25:43 (GMT)
commit8b3fc9cfc357f1659ee6cb9ca707b8ff83776a88 (patch)
tree225f998ad0f3e5142049bac47106d3d07776482a
parent223496a1cf2e128106a7a58ddfad010f5ded4e68 (diff)
version 0.0.90.0.9
-rw-r--r--haddock.sh4
-rw-r--r--redis-hs.cabal14
-rw-r--r--src/Database/Redis/Connection.hs2
-rw-r--r--src/Database/Redis/General.hs21
-rw-r--r--src/Database/Redis/Internal.hs12
-rw-r--r--src/Database/Redis/List.hs19
-rw-r--r--src/Database/Redis/Set.hs8
-rw-r--r--test/redis-tests.cabal4
-rw-r--r--test/suite/Database/Redis/General/Tests.hs8
-rw-r--r--test/suite/Database/Redis/List/Tests.hs10
-rw-r--r--test/suite/Database/Redis/Set/Tests.hs10
-rw-r--r--test/suite/Database/Redis/String/Tests.hs4
12 files changed, 71 insertions, 45 deletions
diff --git a/haddock.sh b/haddock.sh
index 4b6199c..dc7eab6 100644
--- a/haddock.sh
+++ b/haddock.sh
@@ -4,6 +4,4 @@ set -x
rm -Rf dist/doc
-HADDOCK_OPTS='--html-location=http://hackage.haskell.org/packages/archive/$pkg/latest/doc/html'
-
-cabal haddock $HADDOCK_OPTS --hyperlink-source $@
+cabal haddock -v --hyperlink-source $@
diff --git a/redis-hs.cabal b/redis-hs.cabal
index 9484754..28989a0 100644
--- a/redis-hs.cabal
+++ b/redis-hs.cabal
@@ -1,5 +1,5 @@
name: redis-hs
-version: 0.0.8
+version: 0.0.9
author: Will Langstroth <will@langstroth.com>
maintainer: Will Langstroth <will@langstroth.com>
license: MIT
@@ -9,14 +9,12 @@ synopsis: A simple Redis library for Haskell
description:
This package provides access to Redis stores using the Data.ByteString.UTF8
ByteString, for consistent handling of UTF8 encoding. It is a developer pre-
- release, and so lacks many of the features of the existing `redis` package
- (like a monad wrapper, state management, and custom concurrency management)
+ release, so it lacks many of the features of the existing `redis` package
+ (including a monad wrapper, state management, and custom concurrency management)
but for light use, this library makes using Redis very straightforward.
.
- The feature set is incomplete, and version 1.0.0 will be tagged only when the
- library has full command coverage, reasonable test coverage, and solid
- documentation.
-
+ The feature set is incomplete, with full command coverage planned for version
+ 0.1.0, and full documentation and test coverage for 1.0.0.
category: Database
build-type: Simple
@@ -31,9 +29,9 @@ extra-source-files:
test/suite/TestSuite.hs,
test/suite/Database/Redis/Connection/Tests.hs
test/suite/Database/Redis/General/Tests.hs
+ test/suite/Database/Redis/String/Tests.hs
test/suite/Database/Redis/List/Tests.hs
test/suite/Database/Redis/Set/Tests.hs
- test/suite/Database/Redis/String/Tests.hs
library
hs-source-dirs: src
diff --git a/src/Database/Redis/Connection.hs b/src/Database/Redis/Connection.hs
index e3f3b8e..e415b8b 100644
--- a/src/Database/Redis/Connection.hs
+++ b/src/Database/Redis/Connection.hs
@@ -37,5 +37,5 @@ connect host port =
disconnect :: Handle -> IO ()
disconnect h = hClose h
--- QUIT
+
-- AUTH
diff --git a/src/Database/Redis/General.hs b/src/Database/Redis/General.hs
index d1139e4..fa8198b 100644
--- a/src/Database/Redis/General.hs
+++ b/src/Database/Redis/General.hs
@@ -7,6 +7,7 @@ module Database.Redis.General
, keys
, keysB
, keyRandom
+ , keyRename
, select
, toUTF8
, ping
@@ -20,7 +21,8 @@ import Database.Redis.Internal
------------------------------------------------------------------------------
--- | Calls `EXISTS` with a 'String' argument
+-- | Calls @EXISTS@ (<http://code.google.com/p/redis/wiki/ExistsCommand>)
+-- with a 'String' argument
keyExists :: Handle
-> String -- ^ key
-> IO (Maybe RedisReply)
@@ -35,16 +37,17 @@ keyExistsB h key = request h [toUTF8 "EXISTS", key]
------------------------------------------------------------------------------
--- | Calls `DEL` with a /single/ 'String' argument. This function does not
--- yet accept multiple keys.
+-- | Calls @DEL@ (<http://code.google.com/p/redis/wiki/DelCommand>) with a
+-- list of 'String' arguments.
keyDelete :: Handle
- -> String -- ^ key to delete
+ -> [String] -- ^ keys to delete
-> IO (Maybe RedisReply)
-keyDelete h key = request h $ map toUTF8 ["DEL", key]
+keyDelete h ks = request h $ map toUTF8 ("DEL":ks)
------------------------------------------------------------------------------
--- | Calls `TYPE` with a 'String' argument
+-- | Calls @TYPE@ (<http://code.google.com/p/redis/wiki/TypeCommand>) with a
+-- 'String' argument.
keyType :: Handle
-> String
-> IO (Maybe RedisReply)
@@ -74,6 +77,12 @@ keyRandom h = request h [toUTF8 "RANDOMKEY"]
-- RENAME
+keyRename :: Handle
+ -> String -- ^ old key name
+ -> String -- ^ new key name
+ -> IO (Maybe RedisReply)
+keyRename h old new = request h $ map toUTF8 ["RENAME", old, new]
+
-- RENAMENX
-- DBSIZE
-- EXPIRE
diff --git a/src/Database/Redis/Internal.hs b/src/Database/Redis/Internal.hs
index a4b6c77..7b32271 100644
--- a/src/Database/Redis/Internal.hs
+++ b/src/Database/Redis/Internal.hs
@@ -47,11 +47,13 @@ request h commandList = send h $
]
where
sendCommands [] = toUTF8 " "
- sendCommands (c:cs) = B.append (B.concat [ argLength c
- , toUTF8 crlf
- , c
- , toUTF8 crlf
- ]) (sendCommands cs)
+ sendCommands (c:cs) =
+ B.append (B.concat
+ [ argLength c
+ , toUTF8 crlf
+ , c
+ , toUTF8 crlf
+ ]) (sendCommands cs)
bulkLength cmds = toUTF8 $ '*' : (show $ length cmds)
diff --git a/src/Database/Redis/List.hs b/src/Database/Redis/List.hs
index 4e3405d..f4cbd4f 100644
--- a/src/Database/Redis/List.hs
+++ b/src/Database/Redis/List.hs
@@ -15,6 +15,7 @@ module Database.Redis.List
, listRangeB
, listIndex
, listIndexB
+ , listRemove
) where
import System.IO
@@ -117,6 +118,24 @@ listIndexB h key index =
-- LSET
-- LREM
+
+
+------------------------------------------------------------------------------
+-- | Calls `LREM` with 'String' and 'Int' arguments. This command deletes
+-- values matching the @value@ parameter. A negative 'Int' argument deletes
+-- starting at the tail and moving towards the head (or from right to left,
+-- after the push commands). A positive argument deletes from left to right.
+-- Zero deletes all the elements. Returns the number of elements deleted
+-- (which should match the number) or 0 on failure.
+listRemove :: Handle
+ -> String -- ^ key
+ -> Int -- ^ the number of items to delete (sign is direction)
+ -> String -- ^ value
+ -> IO (Maybe RedisReply)
+listRemove h key num value =
+ request h $ map toUTF8 ["LREM", key, show num, value]
+
+
-- LPOP
-- RPOP
-- BLPOP
diff --git a/src/Database/Redis/Set.hs b/src/Database/Redis/Set.hs
index 5a2838d..9155f05 100644
--- a/src/Database/Redis/Set.hs
+++ b/src/Database/Redis/Set.hs
@@ -18,7 +18,7 @@ import Database.Redis.Internal
------------------------------------------------------------------------------
--- SADD
+-- | SADD
setAdd :: Handle
-> String -- ^ key
-> String -- ^ value
@@ -26,7 +26,7 @@ setAdd :: Handle
setAdd h key value = request h $ map toUTF8 ["SADD", key, value]
--- SADD
+-- | SADD
setAddB :: Handle
-> ByteString -- ^ key
-> ByteString -- ^ value
@@ -35,7 +35,7 @@ setAddB h key value = request h [toUTF8 "SADD", key, value]
------------------------------------------------------------------------------
--- SREM
+-- | SREM
setRemove :: Handle
-> String -- ^ key
-> String -- ^ value
@@ -43,7 +43,7 @@ setRemove :: Handle
setRemove h key value = request h $ map toUTF8 ["SREM", key, value]
--- SREM
+-- | SREM
setRemoveB :: Handle
-> ByteString -- ^ key
-> ByteString -- ^ value
diff --git a/test/redis-tests.cabal b/test/redis-tests.cabal
index 32e0c2e..b9922cc 100644
--- a/test/redis-tests.cabal
+++ b/test/redis-tests.cabal
@@ -1,5 +1,5 @@
name: redis-tests
-version: 0.0.8
+version: 0.0.9
build-type: Simple
cabal-version: >= 1.6
@@ -19,5 +19,5 @@ Executable testsuite
test-framework-quickcheck2 >= 0.2.6 && < 0.3,
utf8-string
- ghc-options: -O2 -Wall -fhpc -fwarn-tabs -funbox-strict-fields -threaded
+ ghc-options: -Wall -fhpc
diff --git a/test/suite/Database/Redis/General/Tests.hs b/test/suite/Database/Redis/General/Tests.hs
index 15b97da..68a5302 100644
--- a/test/suite/Database/Redis/General/Tests.hs
+++ b/test/suite/Database/Redis/General/Tests.hs
@@ -33,7 +33,7 @@ keyExistsTest = do
_ <- select con 0
_ <- itemSet con "thekey" "thevalue"
returning <- keyExists con "thekey"
- _ <- keyDelete con "thekey"
+ _ <- keyDelete con ["thekey"]
disconnect con
H.assertEqual "keyExistsTest" (Just $ RedisInteger 1) returning
@@ -45,7 +45,7 @@ keyTypeTest = do
_ <- select con 0
_ <- itemSet con "typekey" "typevalue"
returning <- keyType con "typekey"
- _ <- keyDelete con "typekey"
+ _ <- keyDelete con ["typekey"]
disconnect con
H.assertEqual "keyTypeTest" (Just $ RedisSingle $ toUTF8 "string") returning
@@ -58,8 +58,8 @@ keysTest = do
_ <- itemSet con "keystest0" "value"
_ <- itemSet con "keystest1" "value"
returning <- keys con "keys*"
- _ <- keyDelete con "keystest0"
- _ <- keyDelete con "keystest1"
+ _ <- keyDelete con ["keystest0"]
+ _ <- keyDelete con ["keystest1"]
disconnect con
H.assertEqual "keysTest"
(Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "keystest0")])
diff --git a/test/suite/Database/Redis/List/Tests.hs b/test/suite/Database/Redis/List/Tests.hs
index a672ad8..b7530be 100644
--- a/test/suite/Database/Redis/List/Tests.hs
+++ b/test/suite/Database/Redis/List/Tests.hs
@@ -33,7 +33,7 @@ listRightPushTest = do
con <- connect localhost defaultPort
_ <- select con 0
returning <- listRightPush con "thelist" "theitem"
- _ <- keyDelete con "thelist"
+ _ <- keyDelete con ["thelist"]
disconnect con
H.assertBool "listRightPush" $ case returning of
Just (RedisInteger _) -> True
@@ -46,7 +46,7 @@ listLeftPushTest = do
con <- connect localhost defaultPort
_ <- select con 0
returning <- listLeftPush con "leftlist" "anitem"
- _ <- keyDelete con "leftlist"
+ _ <- keyDelete con ["leftlist"]
disconnect con
H.assertBool "listLeftPush" $ case returning of
Just (RedisInteger _) -> True
@@ -61,7 +61,7 @@ listLengthTest = do
_ <- listRightPush con "lengthlist" "anitem"
_ <- listRightPush con "lengthlist" "anitem"
returning <- listLength con "lengthlist"
- _ <- keyDelete con "lengthlist"
+ _ <- keyDelete con ["lengthlist"]
disconnect con
H.assertEqual "listLeftPush" (Just $ RedisInteger 2) returning
@@ -73,7 +73,7 @@ listIndexTest = do
_ <- select con 0
_ <- listRightPush con "indexlist" "theitem"
returning <- listIndex con "indexlist" 0
- _ <- keyDelete con "indexlist"
+ _ <- keyDelete con ["indexlist"]
disconnect con
H.assertEqual "listIndex"
(Just $ RedisBulk [Just (RedisSingle $ toUTF8 "theitem")])
@@ -88,7 +88,7 @@ listRangeTest = do
_ <- listRightPush con "alist" "value0"
_ <- listRightPush con "alist" "value1"
returning <- listRange con "alist" 0 1
- _ <- keyDelete con "alist"
+ _ <- keyDelete con ["alist"]
disconnect con
H.assertEqual "listRange"
(Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "value0")])
diff --git a/test/suite/Database/Redis/Set/Tests.hs b/test/suite/Database/Redis/Set/Tests.hs
index 0ef7c91..2b79a1b 100644
--- a/test/suite/Database/Redis/Set/Tests.hs
+++ b/test/suite/Database/Redis/Set/Tests.hs
@@ -32,7 +32,7 @@ setAddTest = do
con <- connect localhost defaultPort
_ <- select con 0
returning <- setAdd con "theset" "bob"
- _ <- keyDelete con "theset"
+ _ <- keyDelete con ["theset"]
disconnect con
H.assertEqual "setAdd" (Just $ RedisInteger 1) returning
@@ -44,7 +44,7 @@ setContainsTest = do
_ <- select con 0
_ <- setAdd con "setkey" "bob"
returning <- setContains con "setkey" "bob"
- _ <- keyDelete con "setkey"
+ _ <- keyDelete con ["setkey"]
disconnect con
H.assertEqual "setContains" (Just $ RedisInteger 1) returning
@@ -57,9 +57,9 @@ setMembersTest = do
_ <- setAdd con "nameset" "Bob"
_ <- setAdd con "nameset" "Jane"
returning <- setMembers con "nameset"
- _ <- keyDelete con "setkey"
+ _ <- keyDelete con ["setkey"]
disconnect con
- H.assertEqual "setContains"
+ H.assertEqual "setContains"
(Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "Bob")])
,Just (RedisBulk [Just (RedisSingle $ toUTF8 "Jane")])
,Nothing]))
@@ -76,7 +76,7 @@ setRemoveTest = do
_ <- setAdd con "setit" "Jane"
_ <- setRemove con "setit" "Frank"
returning <- setMembers con "setit"
- _ <- keyDelete con "setit"
+ _ <- keyDelete con ["setit"]
disconnect con
H.assertEqual "setRemove"
(Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "Bob")])
diff --git a/test/suite/Database/Redis/String/Tests.hs b/test/suite/Database/Redis/String/Tests.hs
index b1e1c10..20f94c8 100644
--- a/test/suite/Database/Redis/String/Tests.hs
+++ b/test/suite/Database/Redis/String/Tests.hs
@@ -30,7 +30,7 @@ itemSetTest = do
con <- connect localhost defaultPort
_ <- select con 0
returning <- itemSet con "akey" "ἐστίν"
- _ <- keyDelete con "akey"
+ _ <- keyDelete con ["akey"]
disconnect con
H.assertEqual "itemSet" (Just $ RedisSingle $ toUTF8 "OK") returning
@@ -42,7 +42,7 @@ itemGetTest = do
_ <- select con 0
_ <- itemSet con "differentKey" "ἐστίν"
returning <- itemGet con "differentKey"
- _ <- keyDelete con "differentKey"
+ _ <- keyDelete con ["differentKey"]
disconnect con
H.assertEqual "itemGet" (Just $ RedisBulk [Just (RedisSingle $ toUTF8 "ἐστίν")]) returning