memcache-0.1.0.1: A memcached client library.

Safe HaskellNone
LanguageHaskell2010

Database.Memcache.Client

Contents

Description

A memcached client. Supports the binary protocol (only) and SASL authentication.

A client can connect to a single memcached server or a cluster of them. In the later case, consistent hashing is used to route requests to the appropriate server.

Expected return values (like misses) are returned as part of the return type, while unexpected errors are thrown as exceptions.

Synopsis

Cluster and connection handling

newClient :: [ServerSpec] -> Options -> IO Client Source

Establish a new connection to a group of memcached servers.

type Client = Cluster Source

A memcached client, connected to a collection of memcached servers.

data ServerSpec Source

ServerSpec specifies a server configuration to connect to.

defaultServerSpec :: ServerSpec Source

Provides a default value for a server cconnection config.

data Options Source

Options specifies how a memcached cluster should be configured.

Constructors

Options 

Fields

optsCmdFailure :: !FailureMode
 
optsServerFailure :: !FailureMode
 
optsServerRetries :: !Int
 

defaultOptions :: Options Source

Provides recommended default for a cluster Options.

data Authentication Source

SASL Authentication information for a server.

Constructors

Auth 
NoAuth 

type Username = ByteString Source

Username for authentication.

type Password = ByteString Source

Password for authentication.

quit :: Cluster -> IO () Source

Gracefully close a connection to a memcached cluster.

Get operations

get :: Cluster -> Key -> IO (Maybe (Value, Flags, Version)) Source

Retrieve the value for the given key from memcache.

gat :: Cluster -> Key -> Expiration -> IO (Maybe (Value, Flags, Version)) Source

Get-and-touch: Retrieve the value for the given key from memcache, and also update the stored key-value pairs expiration time at the server.

touch :: Cluster -> Key -> Expiration -> IO (Maybe Version) Source

Update the expiration time of a stored key-value pair, returning its version identifier.

Set operations

set :: Cluster -> Key -> Value -> Flags -> Expiration -> IO Version Source

Store a new (or overwrite exisiting) key-value pair, returning its version identifier.

set' :: Cluster -> Key -> Value -> Flags -> Expiration -> Version -> IO (Maybe Version) Source

Store a key-value pair, but only if the version specified by the client matches the version of the key-value pair at the server. The version identifier of the stored key-value pair is returned, or if the version match fails, Nothing is returned.

add :: Cluster -> Key -> Value -> Flags -> Expiration -> IO (Maybe Version) Source

Store a new key-value pair, returning it's version identifier. If the key-value pair already exists, then fail (return Nothing).

replace :: Cluster -> Key -> Value -> Flags -> Expiration -> Version -> IO (Maybe Version) Source

Update the value of an existing key-value pair, returning it's new version identifier. If the key doesn't already exist, the fail and return Nothing.

Delete operations

delete :: Cluster -> Key -> Version -> IO Bool Source

Delete a key-value pair at the server, returning true if successful.

flush :: Cluster -> Maybe Expiration -> IO () Source

Remove (delete) all currently stored key-value pairs from the cluster.

Modify operations

increment :: Cluster -> Key -> Initial -> Delta -> Expiration -> Version -> IO (Maybe (Word64, Version)) Source

Increment a numeric value stored against a key, returning the incremented value and the version identifier of the key-value pair.

decrement :: Cluster -> Key -> Initial -> Delta -> Expiration -> Version -> IO (Maybe (Word64, Version)) Source

Decrement a numeric value stored against a key, returning the decremented value and the version identifier of the key-value pair.

append :: Cluster -> Key -> Value -> Version -> IO (Maybe Version) Source

Append a value to an existing key-value pair, returning the new version identifier of the key-value pair when successful.

prepend :: Cluster -> Key -> Value -> Version -> IO (Maybe Version) Source

Prepend a value to an existing key-value pair, returning the new version identifier of the key-value pair when successful.

Information operations

version :: Cluster -> IO ByteString Source

Version returns the version string of the memcached cluster. We just query one server and assume all servers in the cluster are the same version.

stats :: Cluster -> Maybe Key -> IO [(Server, Maybe StatResults)] Source

Return statistics on the stored key-value pairs at each server in the cluster.

type StatResults = [(ByteString, ByteString)] Source

StatResults are a list of key-value pairs.

Error handling

data MemcacheError Source

Exceptions that may be thrown by Memcache. These are expected error codes returned by a memcached server.

data ClientError Source

Errors that occur between the client and server in communicating. These are unexpected exceptions, such as network failures or garbage data.

Constructors

NotEnoughBytes