memcache-haskell-0.0.10.1: Memcache procotol library

Safe HaskellNone
LanguageHaskell98

Network.Memcache.Client

Description

This is a utility module for client application.

Synopsis

Documentation

data Client Source

Client is a handler corresponding to a memcached session.

type StatsList = [(String, String)] Source

statistic property list

type Nodekey = String Source

hostname and port (ex. "localhost:11211")

class Hashable a => Key a where Source

Key class

Methods

toBS :: a -> ByteString Source

Instances

openClient Source

Arguments

:: MonadIO m 
=> Nodekey

node key (eg. "127.0.0.1:11211")

-> m (Maybe Client)

client handler

Open a client session and return a client handler.

closeClient Source

Arguments

:: MonadIO m 
=> Client

a client handler

-> m () 

Close a client session.

clientNodekey :: Client -> String Source

Get the hostname and port pair from a handler

clientSocket :: Client -> Handle Source

Get the socket from a handler

withClient Source

Arguments

:: Nodekey

a node

-> (Client -> IO (Maybe a))

an action to be executed with a memcache session

-> IO (Maybe a)

the result of the given action

Connect and execute an action.

withClients Source

Arguments

:: [Nodekey]

a node list

-> (Client -> IO (Maybe a))

an action to be executed with a memcache session

-> IO (Maybe a)

the result of the given action

Connect to one of given hosts and execute an action.

import Network.Memcache
  
main = do
  mValue <- withClient "127.0.0.1:11211" $ \client -> get client "key"
  case mValue of
    Nothing -> putStrLn "(no value)"
    Just value -> putStrLn value

Note that this function doesn't retry the action when it fails.

forEachClient Source

Arguments

:: [Nodekey]

a node list

-> (Client -> IO (Maybe a))

an action to be executed with a memcache session

-> IO [Maybe a]

the result of the given action

Connect to the given hosts one by one and execute the action for each client.

If you'd like to clear all the data in your cluster, you can use this function to issue "flush_all" command to each memcache node.

 main = do
   ret <- forEachClient ["192.168.0.1:11211", "192.168.0.2:11211"] $ flushAll
   print ret

set Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> m Bool

true if the value has been stored

Set an item

setEx Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> Word64

exptime

-> m Bool

true if the value has been stored

Set an item with exptime

cas Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> Word64

a version number got by gets command

-> m Bool

true if the value has been stored

Cas an item

casEx Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> Word64

a version number got by gets command

-> Word64

exptime

-> m Bool

true if the value has been stored

Cas an item with exptime

add Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> m Bool 

Add an item

addEx Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> Word64

exptime

-> m Bool 

Add an item with exptime

replace Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> m Bool

true if the value has been stored

Replace an item

replaceEx Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> v

a value

-> Word64

exptime

-> m Bool

true if the value has been stored

Replace an item with exptime

get Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> m (Maybe v)

the value corresponding to the given key

Get an item

gets Source

Arguments

:: (MonadIO m, Key k, Value v) 
=> Client

a client handler

-> k

a key

-> m (Maybe (v, Word64))

the value and version pair corresponding to the key

Get an item and its version

delete Source

Arguments

:: (MonadIO m, Key k) 
=> Client

a client handler

-> k

a key

-> m Bool

true if the item has been deleted

Delete an item

incr Source

Arguments

:: (MonadIO m, Key k) 
=> Client

a client handler

-> k

a key

-> Int

delta

-> m (Maybe Int)

a resulted value

Increment an item

decr Source

Arguments

:: (MonadIO m, Key k) 
=> Client

a client handler

-> k

a key

-> Int

delta

-> m (Maybe Int)

a resulted value

Decrement an item

flushAll Source

Arguments

:: MonadIO m 
=> Client

a client handler

-> m (Maybe Response)

OK if all items has been removed

Flush all items

stats Source

Arguments

:: MonadIO m 
=> Client

a client handler

-> m StatsList

a property list

Acquire statistic information

To get each statistic value from the resulted list, use Network.Memcache.Stats module.

statsWithArgs Source

Arguments

:: MonadIO m 
=> Client

a client handler

-> [String]

arguments

-> m StatsList

a property list

Acquire statistic information with arguments

To get each statistic value from the resulted list, use Network.Memcache.Stats module.