Safe Haskell | None |
---|---|
Language | Haskell98 |
This is a utility module for client application.
- data Client
- type StatsList = [(String, String)]
- type Nodekey = String
- class Hashable a => Key a where
- toBS :: a -> ByteString
- class Value a where
- serializeValue :: a -> ByteString
- deserializeValue :: ByteString -> Either String a
- openClient :: MonadIO m => Nodekey -> m (Maybe Client)
- closeClient :: MonadIO m => Client -> m ()
- clientNodekey :: Client -> String
- clientSocket :: Client -> Handle
- withClient :: Nodekey -> (Client -> IO (Maybe a)) -> IO (Maybe a)
- withClients :: [Nodekey] -> (Client -> IO (Maybe a)) -> IO (Maybe a)
- forEachClient :: [Nodekey] -> (Client -> IO (Maybe a)) -> IO [Maybe a]
- set :: (MonadIO m, Key k, Value v) => Client -> k -> v -> m Bool
- setEx :: (MonadIO m, Key k, Value v) => Client -> k -> v -> Word64 -> m Bool
- cas :: (MonadIO m, Key k, Value v) => Client -> k -> v -> Word64 -> m Bool
- casEx :: (MonadIO m, Key k, Value v) => Client -> k -> v -> Word64 -> Word64 -> m Bool
- add :: (MonadIO m, Key k, Value v) => Client -> k -> v -> m Bool
- addEx :: (MonadIO m, Key k, Value v) => Client -> k -> v -> Word64 -> m Bool
- replace :: (MonadIO m, Key k, Value v) => Client -> k -> v -> m Bool
- replaceEx :: (MonadIO m, Key k, Value v) => Client -> k -> v -> Word64 -> m Bool
- get :: (MonadIO m, Key k, Value v) => Client -> k -> m (Maybe v)
- gets :: (MonadIO m, Key k, Value v) => Client -> k -> m (Maybe (v, Word64))
- delete :: (MonadIO m, Key k) => Client -> k -> m Bool
- incr :: (MonadIO m, Key k) => Client -> k -> Int -> m (Maybe Int)
- decr :: (MonadIO m, Key k) => Client -> k -> Int -> m (Maybe Int)
- flushAll :: MonadIO m => Client -> m (Maybe Response)
- stats :: MonadIO m => Client -> m StatsList
- statsWithArgs :: MonadIO m => Client -> [String] -> m StatsList
Documentation
Value class
serializeValue :: a -> ByteString Source
deserializeValue :: ByteString -> Either String a Source
Open a client session and return a client handler.
clientNodekey :: Client -> String Source
Get the hostname and port pair from a handler
clientSocket :: Client -> Handle Source
Get the socket from a handler
:: 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.
:: [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.
:: [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
:: (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
:: (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
:: (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
:: (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 an item
:: (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
:: (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
:: (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
:: (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
:: (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 an item
Increment an item
Decrement an item
Flush all items
Acquire statistic information
To get each statistic value from the resulted list, use Network.Memcache.Stats module.
Acquire statistic information with arguments
To get each statistic value from the resulted list, use Network.Memcache.Stats module.