Maintainer | Antoine Latter <aslatter@gmail.com> |
---|
A haskell implementation of the memcahed protocol.
This implements the new binary protocol, so it only works with memcached version 1.3 and newer.
Example of usage, using the network package to obain a handle, and the OverloadedStrings language extension:
h <- connectTo "filename" $ UnixSocket "filename" hSetBuffering h NoBuffering con <- open h
set con "hello" "world" get con "hello"
In the above example we connect to a unix socket in the file "filename", set the key "hello" to the value "world" and then retrieve the value.
Operations are thread safe - multiple threads of execution may make concurrent requests on the memcahced connection.
Operations are blocking, but do not block other concurrent threads from placing requests on the connection.
- open :: Handle -> IO Connection
- close :: Connection -> IO ()
- data Connection
- type Key = ByteString
- type Value = ByteString
- type Result a = IO (Either (ResponseStatus, ByteString) a)
- data ResponseStatus
- set :: Connection -> Key -> Value -> Result ()
- get :: Connection -> Key -> Result ByteString
- delete :: Connection -> Key -> Result ()
- flush :: Connection -> Result ()
- stats :: Connection -> Result [(ByteString, ByteString)]
- version :: Connection -> Result ByteString
Documentation
open :: Handle -> IO ConnectionSource
Create a connection. Please don't use the handle after opening a connection with it.
close :: Connection -> IO ()Source
Shut down the connection. Non-blocking.
data Connection Source
For thread safety of operations, we perform all requests on a wrapper around a handle.
type Key = ByteStringSource
type Value = ByteStringSource
type Result a = IO (Either (ResponseStatus, ByteString) a)Source
data ResponseStatus Source
get :: Connection -> Key -> Result ByteStringSource
Retrive a value from the cache
flush :: Connection -> Result ()Source
Delete all entries in the cache
stats :: Connection -> Result [(ByteString, ByteString)]Source
Returns a list of stats about the server in key,value pairs
version :: Connection -> Result ByteStringSource
Returns the version of the server