author | Alberto Bertogli
<albertito@gmail.com> 2007-09-02 00:02:47 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-09-02 00:02:47 UTC |
parent | ed5cae01d319c931ee22a2adea797a21e713e940 |
bindings/haskell/Nmdb.hs | +17 | -0 |
tests/haskell/test1.hs | +6 | -0 |
diff --git a/bindings/haskell/Nmdb.hs b/bindings/haskell/Nmdb.hs index 14bf979..735385a 100644 --- a/bindings/haskell/Nmdb.hs +++ b/bindings/haskell/Nmdb.hs @@ -11,6 +11,7 @@ module Nmdb ( nmdbGet, nmdbCacheGet, nmdbDel, nmdbDelSync, nmdbCacheDel, nmdbCAS, nmdbCacheCAS, + nmdbIncr, nmdbCacheIncr, ) where import Foreign.Ptr @@ -155,3 +156,19 @@ nmdbCAS = nmdbGenericCAS llNmdbCAS nmdbCacheCAS = nmdbGenericCAS llNmdbCacheCAS +-- Incr functions +foreign import ccall "nmdb.h nmdb_incr" llNmdbIncr :: + NmdbPtr -> CString -> Int -> Int -> IO Int +foreign import ccall "nmdb.h nmdb_cache_incr" llNmdbCacheIncr :: + NmdbPtr -> CString -> Int -> Int -> IO Int + +nmdbGenericIncr llfunc db key increment = do + kl <- newCStringLen key + r <- llfunc db (fst kl) (snd kl) increment + free (fst kl) + return r + +nmdbIncr = nmdbGenericIncr llNmdbIncr +nmdbCacheIncr = nmdbGenericIncr llNmdbCacheIncr + + diff --git a/tests/haskell/test1.hs b/tests/haskell/test1.hs index 9a49f47..f824a98 100644 --- a/tests/haskell/test1.hs +++ b/tests/haskell/test1.hs @@ -20,6 +20,7 @@ main = do cshow "Add TIPC" $ nmdbAddTIPCServer db (-1) cshow "Add TCP" $ nmdbAddTCPServer db "localhost" (-1) cshow "Add UDP" $ nmdbAddUDPServer db "localhost" (-1) + cshow "Add SCTP" $ nmdbAddSCTPServer db "localhost" (-1) cshow "Set 'Hello' 'Bye'" $ nmdbSet db "Hello" "Bye" @@ -31,6 +32,11 @@ main = do cshow "Del 'Hello'" $ nmdbDel db "Hello" + + cshow "Set 'Hello' '10\\0'" $ nmdbSet db "Hello" "10\0" + cshow "Incr 'Hello' 10" $ nmdbIncr db "Hello" 10 + cshow "Get 'Hello'" $ nmdbGet db "Hello" + cshow "Free" $ nmdbFree db return ()